javascript - disable textfield until select option from select list -


i have list of option inside select list, have textfield contain option value when selected. make textfield disable default , when i'm selecting 1 of options - textfield enable. can direct me simiar example?

thanks

here example using plain javascript jsfiddle:

html:

<select id='myselect'>     <option value='none'>none</option>     <option value='1'>1</option>     <option value='2'>2</option>     <option value='3'>3</option> </select> <input type='text' value='' name='mytext' id='mytext' disabled /> <button value='add' id='addbtn' name='addbtn'>add</button> 

we started disabled input textfield.

var myselect = document.getelementbyid('myselect');  function createoption() {     var currenttext = document.getelementbyid('mytext').value;     var objoption = document.createelement("option");     objoption.text = currenttext;     objoption.value = currenttext;      //myselect.add(objoption);     myselect.options.add(objoption); }  document.getelementbyid('addbtn').onclick = createoption;  myselect.onchange = function() {     var mytextfield = document.getelementbyid('mytext');     if (myselect.value == 'none'){         mytextfield.value = '';         mytextfield.disabled = true;     }else {         mytextfield.value = myselect.value;         mytextfield.disabled = false;     } } 

using example on previous post add onchange state select tag when option selected set textfield's value selected, , set textfield's disable false. thus, enable textfield when option selected. additionally, added option called 'none' when user selects none it'll diable textfield.


Comments

Popular posts from this blog

Javascript line number mapping -

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -