Jump to content
  • Advertisement
Sign in to follow this  
johnnyBravo

[web] How to remove object from combobox using html/javascript?

This topic is 4963 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I've got a combobox full of values like "44B","23C" etc Using javascript with html, Say I want to remove the option with value "44B" is there any way of removing it by just using its value, otherwise how would i remove it anyway. thanks

Share this post


Link to post
Share on other sites
Advertisement
You can delete it via index.

Sample deletion via form button:


<html>
<head>
<script language="javascript">
function deleteoption(index)
{

var sel = document.form1.select;
sel.options[index] = null;


}
</script>
<title>Untitled Document</title>
</head>

<body>
<form name="form1" method="post" action="javascript:deleteoption(document.form1.Option.value);">
<select name="select">
<option>Blah</option>
<option>Blah2</option>
<option>Blah3</option>
</select>
<br>
<br>
<input name="Option" type="text" size="20" maxlength="20">
<br>
<br>
<input type="submit" name="Submit" value="Delete Item">
</form>
</body>
</html>

Share this post


Link to post
Share on other sites
Scan through all the options in the box, to find the ones you want to remove, and remove them.

For best effect, work backwards from the highest numbered one, that way removing options won't cause elements to be renumbered while you're traversing the array.

Mark

Share this post


Link to post
Share on other sites
Oh so when you make the option[] null it actually removes it and renumbers everything...

Im wondering if theres a way of hiding the text/value option from the user selecting it, and so then i can remake it visible without having to reupdate the list?

thx

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!