Drop down/select - add option

N

Nanos

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
 
I

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
 
N

Nanos

Thank you Ivo, will try it shortly,
emanuel

Ivo said:
"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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top