> Internet Exploer does not like this method for some reason
Why? What made you reach that conclusion? In fact, my entire snippet for removing the selected option relies on removeChild and it works fine in IE/FF/Opera.
Also a few things to keep in mind.Post the entire code which we can copy and run instead of just the relevant function which in turn requires us to develop a test case.
Don't use tabs for indentation, at least when posting code. It makes a mess out of it as you can very well see.
Here is a small snippet which should get you going:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Example</title>
<script type="text/javascript">
function doDelete(frm) {
var sel = frm && frm.elements["selBox"];
/* empty / non-existent select box */
if(!sel || sel.selectedIndex < 0) {
return;
}
var item = sel.options[sel.selectedIndex];
var parent = item.parentNode;
parent.removeChild(item);
/* remove all the text nodes */
while(parent.hasChildNodes()) {
if(parent.childNodes[0].nodeType != 3) {
/* non-text node found, exit the function */
return;
}
parent.removeChild(parent.childNodes[0]);
}
/* since we have reached here, the parent node
must have zero elements so remove it */
parent.parentNode.removeChild(parent);
}
</script>
</head>
<body>
<form action="#" name="frm">
<select name="selBox">
<optgroup label="Swedish Cars">
<option value ="volvo">Volvo</option>
<option value ="saab">Saab</option>
</optgroup>
<optgroup label="German Cars">
<option value ="mercedes">Mercedes</option>
<option value ="audi">Audi</option>
</optgroup>
</select>
<input type="button" value="Delete Selected" onclick="doDelete(this.form);">
</form>
</body>
</html> ~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734