Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-26-2002, 01:27 PM   PM User | #1
Ben Chivers
New Coder

 
Join Date: Jun 2002
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Ben Chivers is an unknown quantity at this point
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
Ben Chivers is offline   Reply With Quote
Old 06-26-2002, 01:35 PM   PM User | #2
whackaxe
Senior Coder

 
Join Date: Jun 2002
Location: paris, france
Posts: 1,216
Thanks: 0
Thanked 0 Times in 0 Posts
whackaxe is an unknown quantity at this point
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
whackaxe is offline   Reply With Quote
Old 06-26-2002, 03:07 PM   PM User | #3
tamienne
Regular Coder

 
Join Date: Jun 2002
Location: Delaware, USA
Posts: 138
Thanks: 0
Thanked 0 Times in 0 Posts
tamienne is an unknown quantity at this point
<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()">
tamienne is offline   Reply With Quote
Old 06-26-2002, 03:33 PM   PM User | #4
whackaxe
Senior Coder

 
Join Date: Jun 2002
Location: paris, france
Posts: 1,216
Thanks: 0
Thanked 0 Times in 0 Posts
whackaxe is an unknown quantity at this point
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
whackaxe is offline   Reply With Quote
Old 06-26-2002, 03:51 PM   PM User | #5
tamienne
Regular Coder

 
Join Date: Jun 2002
Location: Delaware, USA
Posts: 138
Thanks: 0
Thanked 0 Times in 0 Posts
tamienne is an unknown quantity at this point
i didn't test in NS but in ie it looks good. Changing the selectedIndex reset the list and deleted the blank line.
tamienne is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:18 PM.


Advertisement
Log in to turn off these ads.