html - add text from textfield into selectbox at javascript? -
can point @ tutorial adding text (by user) textfield select list (after clicking button) javascript?
thanks
here simple jsfiddle shows how can dynamically add option select tag using javascript input textfield:
html:
<select id='myselect'></select> <input type='text' value='' name='mytext' id='mytext' /> <button value='submit' id='mybtn' name='submit'>submit</button>
javascript:
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('mybtn').onclick = createoption;
basically have text field, button , select box in html. submit button attached onclick event calls createoption function. createoption function creates option element , add select box option text , value equal text text field. using document.getelementsbyid
able inject newly created element selectbox , retrive inserted value textfield.
however, if looking written tutorial reference using javascript dynamically populate form creating form dynamically
Comments
Post a Comment