Web Analytics Made Easy -
StatCounter Deleting Options in Drop Down Menus - CodingForum


No announcement yet.

Deleting Options in Drop Down Menus

  • Filter
  • Time
  • Show
Clear All
new 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
    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
      function deleteit() {
      document.forms[0].elements[0].options[document.forms[0].elements[0].options.selectedIndex] = null;
      document.forms[0].elements[0].options.selectedIndex = 0;

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

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


      • #4
        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
          i didn't test in NS but in ie it looks good. Changing the selectedIndex reset the list and deleted the blank line.