Aline: IE vergisst den Text

Beitrag lesen

Hi!

Warum vergisst der Internet Explorer den Text, wenn auf die Dropdownbox mehr als 1 mal geklickt wird?
So richtig habe ich nicht verstanden, was Du eigentlich erreichen willst.

ich habe bei jeder optgroup eine Standardoption, die entfernt werden soll, wenn eine option unterhalb dieser optgroup hinzugefügt wird. Werden alle option einer optgroup entfernt, soll die Standardoption automatisch wieder eingefügt werden.

Mein Beispiel ist stark gekürzt, zeigt jedoch das fehlerhafte Verhalten des IEs.

Allerdings würde ich im DOM nicht einfach ein Element gleich null setzen

ich hab das Beispiel aus selfhtml entnommen

Um Elemente zu entfernen gibt es http://de.selfhtml.org/javascript/objekte/node.htm#remove_child@title=removeChild().

function deleteDummyOption(obj){
  var optgroups = obj.getElementsByTagName("optgroup");
  var counter = 0;
  var options;

for (var i = 0; i < optgroups.length; i++){
    options = optgroups[i].getElementsByTagName("option");
    counter += options.length;

if(options.length == 1){
      //obj.options[counter-1] = null;
         optgroups[i].removeChild(options[counter-1]);
    }
  }
}

»»»»

wenn eine Dropdownbox 2 optgroups hat, wird ein Fehler geworfen, wenn die Kinder der 2. optgroup entfernt werden  
  
Iceweasel:  

> [Exception... "Component returned failure code: 0x80004003 (NS\_ERROR\_INVALID\_POINTER) [nsIDOMHTMLOptGroupElement.removeChild]"  nsresult: "0x80004003 (NS\_ERROR\_INVALID\_POINTER)"  location: "JS frame :: http://localhost:8888/script.js :: anonymous :: line 387"  data: no]  
> http://localhost:8888/script.js  
> Line 387  
  
Opera 10.00 Beta 2 (Build 4520):  

> JavaScript - http://localhost:8888/:export-profiles.html  
> Unknown thread  
> Error:  
> name: Error  
> message: WRONG\_ARGUMENTS\_ERR  
> stacktrace: n/a; see  opera:config#UserPrefs|Exceptions Have Stacktrace  
  
  
Internet Explorer:  

> Webpage error details  
>  
> User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)  
> Timestamp: Sun, 2 Aug 2009 07:59:14 UTC  
>  
> Message: Type mismatch.  
>  
> Line: 387  
> Char: 9  
> Code: 0  
> URI: http://new:8888/script.js  
  
  
Zeile 387 ist folgende:  
`optgroups[i].removeChild(options[counter-1]);`{:.language-javascript}  
  
Wenn ich statt "`optgroups[i].removeChild(options[counter-1]);`{:.language-javascript}" das Element wie folgt entferne "`obj.options[counter-1] = null;`{:.language-javascript}" funktioniert das entfernen und einfügen einer anderen Option  
  
Aline