HighDots Forums  

option.text im IE nicht untertützt?

Javascript (German) Programmiersprache JavaScript. (de.comp.lang.javascript)


Discuss option.text im IE nicht untertützt? in the Javascript (German) forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Bernhard Brockmann
 
Posts: n/a

Default option.text im IE nicht untertützt? - 01-06-2008 , 03:33 AM






Guten morgen,

ich habe eine Funktion geschrieben, die den Inhalt von einer Auswahl in
eine andere veschiebt. Im Firefox funktioniert es aber im IE nicht. Da
wird zwar die Eigenschaft value gesetzt aber de Eigenschaft text nicht.

Was mache ich falsch? Danke.

function addProduct() {
dataProductSelection = document.getElementById('dataProducts');
productSelection = document.getElementById('products');
action = false;
for (i=0; i<productSelection.length; i++) {
if (productSelection[i].selected==true) {
newDataProduct = document.createElement('option');
newDataProduct.text = productSelection[i].text;
newDataProduct.value = productSelection[i].value;
newDataProduct.selected = true;
alert(newDataProduct.text+' '+newDataProduct.value+'
'+newDataProduct.selected);
dataProductSelection.appendChild(newDataProduct);
productSelection[i] = null;
action = true;
}
}
}

Reply With Quote
  #2  
Old   
Bernhard Brockmann
 
Posts: n/a

Default Re: option.text im IE nicht untertützt? - 01-06-2008 , 03:38 AM






Bernhard Brockmann schrieb:
Quote:
alert(newDataProduct.text+'
'+newDataProduct.value+' '+newDataProduct.selected);
Nachtrag: n der Box it die Eigenschaft text noch gefüllt, aber im IE
wird sie nicht mehr angezeigt.

Danke.


Reply With Quote
  #3  
Old   
horst lorenz
 
Posts: n/a

Default Re: option.text im IE nicht untertützt? - 01-06-2008 , 05:11 AM



On 6 Jan., 10:33, Bernhard Brockmann <b.brockm... (AT) flb-essen (DOT) de> wrote:
Quote:
function addProduct() {
* * *dataProductSelection = document.getElementById('dataProducts');
* * * * * * * * productSelection = document.getElementById('products');
* * * * * * * * action = false;
* * * * * * * * for (i=0; i<productSelection.length; i++) {
productSelection.length ?????

Quote:
* * * * * * * * * * if (productSelection[i].selected==true) {
produktSelection[i] ?????????

getElementById liefert doch kein Array.

Im übrigen wäre es hilfreich, wenn Du eine URL angeben kannst, wo man
die komplette Seite sehen kann.

Tschüß Horst.


Reply With Quote
  #4  
Old   
Bernhard Brockmann
 
Posts: n/a

Default Re: Re: option.text im IE nicht untertützt? - 01-06-2008 , 06:03 AM



horst lorenz schrieb:
Quote:
On 6 Jan., 10:33, Bernhard Brockmann <b.brockm... (AT) flb-essen (DOT) de> wrote:
function addProduct() {
dataProductSelection = document.getElementById('dataProducts');
productSelection = document.getElementById('products');
action = false;
for (i=0; i<productSelection.length; i++) {

productSelection.length ?????

if (productSelection[i].selected==true) {

produktSelection[i] ?????????

getElementById liefert doch kein Array.

Hallo Horst,

getElementById liefert hier ein Objekt vom Typ Select, welches unter
Anderem die Eigenschaft options besitzt. Durch diese Optons kann
iterieren, wie durch ein Array wie in meiner Funktion verwendet.

Ich habe meine Frage in der zwschenzeit selbst beantwortet.
Die Funktion appendChild funktioniert im IE im Zusammenhang mit dem
Objekt vom Typ Option nicht korrekt zusammen. Deshalb verwende ich nun
die Methode add des Objekts Select. Hier muss man aber auch wieder
zwischen IE und Anderen unterscheiden. also dieht die Lösung wie folgt aus:

try {
productSelection.add(newDataProduct, null);
}
catch(e) {
productSelection.add(newDataProduct);
}

statt

dataProductSelection.appendChild(newDataProduct);


nun funktionierts.

Danke trotzdem.

Bernhard


Reply With Quote
  #5  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

Default Re: Re: option.text im IE nicht untertützt? - 01-06-2008 , 07:35 AM



Bernhard Brockmann wrote:
Quote:
horst lorenz schrieb:
On 6 Jan., 10:33, Bernhard Brockmann <b.brockm... (AT) flb-essen (DOT) de> wrote:
function addProduct() {
dataProductSelection = document.getElementById('dataProducts');
productSelection = document.getElementById('products');
action = false;
for (i=0; i<productSelection.length; i++) {
Wo werden `dataProductSelection', `productSelection', `action' und `i'
deklariert?

Quote:
productSelection.length ?????

if (productSelection[i].selected==true) {
produktSelection[i] ?????????

getElementById liefert doch kein Array.

[...]
getElementById liefert hier ein Objekt vom Typ Select,
Die Bezeichnung "Objekt vom Typ" ist schlicht falsch.

Quote:
welches unter Anderem die Eigenschaft options besitzt. Durch diese Optons
kann iterieren, wie durch ein Array wie in meiner Funktion verwendet.
Du verwendest `options' aber nicht, sondern Du verwendest eine nicht
existierende length-Eigenschaft eines select-Elementobjekts, welches
möglicherweise (in Firefox auf jeden Fall) das HTMLSelectElement-Interface
von W3C DOM Level 2 HTML implementiert.

Quote:
Ich habe meine Frage in der zwschenzeit selbst beantwortet. Die Funktion
appendChild funktioniert im IE im Zusammenhang mit dem Objekt vom Typ
Option nicht korrekt zusammen.
Es handelt sich um ein option-Elementobjekt, nicht um ein "Objekt vom Typ
Option".

Quote:
Deshalb verwende ich nun die Methode add des Objekts Select. Hier muss
man aber auch wieder zwischen IE und Anderen unterscheiden.
Ja, weil IE hier das MSHTML-DOM implementiert und nicht das W3C DOM.

Quote:
also dieht die Lösung wie folgt aus:

try { productSelection.add(newDataProduct, null); } catch(e) {
productSelection.add(newDataProduct); }

statt

dataProductSelection.appendChild(newDataProduct);

nun funktionierts.
Es funktioniert da nicht, wo Exception-Handling nicht unterstützt wird, z.B.
nicht in IE vor Version 5; dort gibt es einen Syntaxfehler. Das Folgende
funktioniert hingegen "immer" und "überall" (DOM Level 0):

var opts = productSelection.options;
opts[opts.length] = new Option("foo", "bar", ...);

http://docs.sun.com/source/816-6408-10/option.htm


PointedEars
--
Andererseits wäre auf einer Seite unter vu-Domain mit Zappelgifs,
Mustertapete, MS Sans Comic und Frames ein fehlender Counter ein
glatter Stilbruch.
(Olaf Pöhlmann in dciwam <asl6a6$rm0$04$1 (AT) news (DOT) t-online.com>)


Reply With Quote
Reply




Thread Tools
Display Modes

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

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



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.