...

View Full Version : IE7 Crashes ith select box



edric
07-20-2009, 12:41 PM
A problem with these code in IE7



<select id="testSelect">
<option value="one">1st option</option>
<option value="two">2nd option</option>
</select>

<input type="button" value="remove" onclick="remove2()" />

<script language="javascript">
function remove2(){
selectBox = document.getElementById("testSelect");
if(selectBox.options.length > 1) {
selectBox.remove(1);
}
}
</script>


When :
1. select option 2
2. select option 1
3. press remove button

Internet Explorer 7 crashes without saying why.

randomuser773
07-20-2009, 01:04 PM
When :
1. select option 2
2. select option 1
3. press remove button

Internet Explorer 7 crashes without saying why.
Unable to reproduce the problem.

You can use selectBox.options[1]=null; but it should not make any difference.

Kor
07-20-2009, 10:00 PM
1. language is deprecated. You should use type instead


script type="text/javascript">
...
</script>



selectBox.remove(1);

2. What do you intend to do with that remove() method/function/whichever?. Remove what?

edric
07-21-2009, 11:14 AM
I'm removing option in select box (it works the same as selectBox.options[1]=null)

Its a very old code that needed a changed.
I rewrite the code to use DOM objects (creating appending elements and nodes etc..) . so this solved.

Philip M
07-21-2009, 12:30 PM
Like Kor I do not really understand what you are trying to do. Perhaps try this:-


<form name='myform'>
<select name = 'list1' id = 'list1' onchange = "removeOptions(this)">
<option selected value=""> Choose A Fruit</option>
<option value='Mango'> Mango </option>
<option value='Apple'> Apple </option>
<option value='Orange'> Orange </option>
<option value='Watermelon'> Watermelon </option>
</select>
</form>

<script type = "text/javascript">
var val = "";
function removeOptions(selectbox) {
val = selectbox.value;
for (var i = selectbox.options.length-1; i>=1; i--) {
if (selectbox.options[i].selected) {
selectbox.remove(i);
document.myform.list1.focus();
}
}
}

</script>
"Funding is to be cut for sports where targets have been missed, such as archery". - Government spokesman

edric
07-21-2009, 03:30 PM
What don't you understand ?

I found out element.removeChild(...) works better.
Case Solved



BTW: The IE Crash happens only if I try to remove second option out of two options.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum