JQuery select function not showing div -
i have jquery function (with of stackoverflow post) hides/shows divs depending on selected on select/dropdown. works fine.
when edit record stored value of select field displayed in select/dropdown corresponding div remains hidden until change made on select field.
code
<script> $(document).ready(function () { $('.jshideshow').hide(); $('#id_selection_basis').change(function () { $('.jshideshow').hide(); $('#'+$(this).val()).show(); }) }); </script>
i have tried various combinations of above code show div straight away on update view value have far been unsuccessful.
any appreciated!
please post corresponding html, i'm having trouble understanding exact issue broke down code doing might able figure out there.
<script> $(document).ready(function () { $('.jshideshow').hide(); // 1 $('#id_selection_basis').change(function () { $('.jshideshow').hide(); // 2 $('#'+$(this).val()).show(); // 3 }) }); </script>
since you're hiding
.jshideshow
default, setdisplay: none
either inline on element in html or add css class (this isn't causing issue though)this hides
.jshideshow
- why need hide that's hidden? makes sense if divs show/hide have class they're hidden before call.show()
on target element (see #3)this displays whatever element contained in value of
#id_selection_basis
if you're adding elements #id_selection_basis
need listen change event $(document).on('change', '#id_selection_basis', function () { ... })
. event listeners bound dom on page load if add element dom after page load, need listen on $(document)
.
Comments
Post a Comment