Text Field to Dropdown

Here’s a very simple method for adding (populating) content to a drop down option box in your form via a text-field using JavaScript. It was something I required a while back and found very little examples on the Internet.


function Add_to_drop_down()
Name_text = document.getElementById('Box_text').value;
Val_text = Name_text
obj = document.getElementById("my_drop_down");
obj.options[obj.options.length] = new Option(Name_text,Val_text)


<input type=text id="Box_text">
<input type=button onclick="Add_to_drop_down()" value="Add &raquo;">
<select name="my_drop_down" id="my_drop_down"></select>