Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jun 2002
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Deleting Options in Drop Down Menus

    Does anyone know how to delete options from a drop down menu at the click of a button.

    Any help would be most appreciated.

    Many Regards,
    Ben Chivers

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    paris, france
    Posts
    1,216
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you cant delete the space i think but you can erase the text and value (you should actully keep the value and change it to something like "voidoption" so you can check if its void) anway you can change an option by using this

    document.theform.theselect.options[0].value = "nufink"
    document.theform.theselect.options[0].text = ""

    to change the vakue of the current selected option use this!

    document.theform.theselect.options[theform.theselect.selectedIndex].value = "nufink"

    theform.theslect.selectedIndex is the numbe of the currently selected option (well, at te time it is called) it starts at 0 and goes up with more oprions added
    photoshop too expensive? use the GIMP! www.gimp.org

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Delaware, USA
    Posts
    137
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <Script>
    function deleteit() {
    document.forms[0].elements[0].options[document.forms[0].elements[0].options.selectedIndex] = null;
    document.forms[0].elements[0].options.selectedIndex = 0;
    }
    </script>

    <select>
    <option value="volvo">Volvo</option>
    <option value="saab">Saab </option>
    <option value="fiat">Fiat </option>
    <option value="audi">Audi </option>
    </select>

    <input type="button" value="delete it!" onClick="deleteit()">

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    paris, france
    Posts
    1,216
    Thanks
    0
    Thanked 0 Times in 0 Posts
    does that remove the blank space that is left if you use text=""" and value="" as i said?
    photoshop too expensive? use the GIMP! www.gimp.org

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    Delaware, USA
    Posts
    137
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i didn't test in NS but in ie it looks good. Changing the selectedIndex reset the list and deleted the blank line.


  •  

    Posting Permissions

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