Drop down/select - add option

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nanos

    Drop down/select - add option

    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



  • Ivo

    #2
    Re: Drop down/select - add option

    "Nanos" asks:[color=blue]
    > 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.[/color]

    <script type="text/javascript">
    function changed(el){
    if(el.options[el.selectedInde x].value=='other' ) {addoption(el); }
    }
    function addoption(el){
    var txt=prompt('Ple ase enter the text of the new option:','Add me!');
    if(txt==null) {return;}
    var val=prompt('Ple ase enter the value of the new option:','examp le');
    // if(val==null) {return;}
    var o=new Option( txt, val, false, true);
    el.options[el.options.leng th]=o;
    }
    </script>

    <select name="mylist" onchange="chang ed(this)">
    <option value="some">mo re of
    <option value="the same">the same
    <option value="other">o ther
    </select>

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


    Comment

    • Nanos

      #3
      Re: Drop down/select - add option

      Thank you Ivo, will try it shortly,
      emanuel

      "Ivo" <no@thank.you > wrote in message
      news:4105b3d9$0 $66819$a344fe98 @news.wanadoo.n l...[color=blue]
      > "Nanos" asks:[color=green]
      > > 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.[/color]
      >
      > <script type="text/javascript">
      > function changed(el){
      > if(el.options[el.selectedInde x].value=='other' ) {addoption(el); }
      > }
      > function addoption(el){
      > var txt=prompt('Ple ase enter the text of the new option:','Add me!');
      > if(txt==null) {return;}
      > var val=prompt('Ple ase enter the value of the new option:','examp le');
      > // if(val==null) {return;}
      > var o=new Option( txt, val, false, true);
      > el.options[el.options.leng th]=o;
      > }
      > </script>
      >
      > <select name="mylist" onchange="chang ed(this)">
      > <option value="some">mo re of
      > <option value="the same">the same
      > <option value="other">o ther
      > </select>
      >
      > This is a simple approach. All sorts of details can be done differently.
      > HTH
      > Ivo
      >
      >[/color]


      Comment

      Working...