By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,510 Members | 1,815 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,510 IT Pros & Developers. It's quick & easy.

Drop down/select - add option

P: n/a
Hi all,
For the form I need to create drop down select with different options
(dynamicly from DB). That's easy in PHP. But there also should be the
possibility to enter own option if one is not
listed. Is there a way to do it. Did anyone come accross of any tool/script?
Thank you in advance for any hint,
emanuel

Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Ivo
"Nanos" asks:
Hi all,
For the form I need to create drop down select with different options
(dynamicly from DB). That's easy in PHP. But there also should be the
possibility to enter own option if one is not listed.


<script type="text/javascript">
function changed(el){
if(el.options[el.selectedIndex].value=='other') {addoption(el);}
}
function addoption(el){
var txt=prompt('Please enter the text of the new option:','Add me!');
if(txt==null) {return;}
var val=prompt('Please enter the value of the new option:','example');
// if(val==null) {return;}
var o=new Option( txt, val, false, true);
el.options[el.options.length]=o;
}
</script>

<select name="mylist" onchange="changed(this)">
<option value="some">more of
<option value="the same">the same
<option value="other">other
</select>

This is a simple approach. All sorts of details can be done differently.
HTH
Ivo
Jul 23 '05 #2

P: n/a
Thank you Ivo, will try it shortly,
emanuel

"Ivo" <no@thank.you> wrote in message
news:41***********************@news.wanadoo.nl...
"Nanos" asks:
Hi all,
For the form I need to create drop down select with different options
(dynamicly from DB). That's easy in PHP. But there also should be the
possibility to enter own option if one is not listed.


<script type="text/javascript">
function changed(el){
if(el.options[el.selectedIndex].value=='other') {addoption(el);}
}
function addoption(el){
var txt=prompt('Please enter the text of the new option:','Add me!');
if(txt==null) {return;}
var val=prompt('Please enter the value of the new option:','example');
// if(val==null) {return;}
var o=new Option( txt, val, false, true);
el.options[el.options.length]=o;
}
</script>

<select name="mylist" onchange="changed(this)">
<option value="some">more of
<option value="the same">the same
<option value="other">other
</select>

This is a simple approach. All sorts of details can be done differently.
HTH
Ivo

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.