www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] ComboBox “New Option” Option w/ Popup Input to add option

  1. #1
    Join Date
    Nov 2010
    Posts
    2

    resolved [RESOLVED] ComboBox “New Option” Option w/ Popup Input to add option

    I am searching a solution to change a ComboBox by popup

    I have found this script on the web. Is it also possible to select the newVendor just after adding? Is this script ok or are there better solutions?



    <script type="text/javascript">
    <!--
    function message(value){
    if(value=="newVendor"){// New Vendor is selected
    var vendor = prompt("Vandor's Name","");

    var elementSelect = document.getElementById('vendor');

    try{
    elementSelect.add(new Option(vendor, vendor), elementSelect.options[2])
    }
    catch(ex){
    elementSelect.add(new Option(vendor, vendor), 2)
    }
    }
    }
    //-->
    </script>



    <div>
    <form>
    <select id="vendor" name="vendor" onChange="message(this.value);">
    <option value="scp">SCP</option>
    <option value="keller">Keller</option>
    <option value="newVendor">New Vendor</option>
    </select>
    </form>
    </div>

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    function message(value){
    if(value=="newVendor"){// New Vendor is selected
    var vendor = prompt("Vandor's Name","");
    
    var elementSelect = document.getElementById('vendor');
    
    try{
    elementSelect.add(new Option(vendor, vendor, false , true ), elementSelect.options[2])
    }
    catch(ex){
    elementSelect.add(new Option(vendor, vendor, false , true ), 2)
    }
    elementSelect.options.selectedIndex = 2;
    }
    }
    http://devedge-temp.mozilla.org/libr...ce/option.html
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #3
    Join Date
    Nov 2010
    Posts
    2
    Great, it works! Thank you very very much for your help !!!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles