Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can you add an input field into a pulldown list?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi,

I've created a pulldown list as part of a form but I want users to be able to type in their own choice if it's not available from the list. Is this possible?

My current code is:

<form onSubmit=&quot;return checkrequired(this)&quot; name=&quot;frmMail&quot; method=&quot;post&quot; action=&quot;addcontact.asp&quot;>
<select name=&quot;requiredrecipient&quot; width=30>
<option selected>Administration</option><option>Services</option><option>Chairman</option>
<option>Products</option><option>Corporate Marketing</option>
</select>

Basically if the above choices are not acceptable for users, I want them to input their own choice.

Thanks,

 
Well, you could put a text box next to it, and have a button that they would press that would call some javascript to actually add it to the list box, but that seems to be a little redundant --

Probably just put the text box there, and let them either choose one from the list, or type in their own (without adding it to the listbox) --

But here's how you would add it just in case --

<input type=text name=addition><input type=button value=&quot;Add it&quot; onClick=&quot;addIt();&quot;>

<script language=javascript>
function addIt(){
document.frmMail.requiredrecipient.options.add(document.frmMail.addition.value, document.frmMail.addition.value);
}
</script>

After they click the button -- the new option would appear in the list.

good luck! :)
Paul Prewett
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top