javascript - populate and disable text field depending on dropdown -
unfortunately i'm not familiar javascript/jquery. have form dropdown. need populate text field depending on selection of dropdown. first voice of dropdown "other" text field must writable, second want assign value automatically , disable text field.
the value of dropdown saved in db must remains name of option.
i found several solutions google none of them fits needs...hope me.
to create functionality you're looking for, there few basic things you'll need learn.
jquery selectors
first, if aren't familiar jquery's selector syntax, learn here.
the .change() event
next, you'll need know how bind dropdown menu's .change
event. 1 way $('#dropdownid').change(function() { ... });
, shortcut $('#dropdownid').on('change', function() { ... });
. within callback functions, can access dropdown element this
, result, jquery object $(this)
.
we can grab dropdown's value $(this).val() , use basic logic enable/disable textbox , set value.
enabling/disabling textbox
in order enable/disable textbox, can use: $('#txt').removeattr('disabled');and
$('#txt').attr('disabled', 'true');` respectively.
example
i've combined of these in example fiddle show how can put these in jsfiddle. let me know if have questions how works :)
Comments
Post a Comment