javascript - Problems with option selection in Chrome and Opera -


i've problems thise code, it's working fine in firefox , internet explorer doesn't work opera , chrome browsers...

<script> function planetselect() { optionen=document.getelementbyid('pstart').options; for(i=0;i<optionen.length;i++) { if(optionen[i].value==67080) {   optionen[i].setattribute('selected','selected');   } } optionen=document.getelementbyid('pdest').options; for(i=0;i<optionen.length;i++) { if(optionen[i].value==67080) {   optionen[i].setattribute('selected','selected');   } } }</script> 

change

optionen[i].setattribute('selected','selected'); 

to

optionen[i].selected = true; 

more generally, avoid use of setattribute change dom properties. works, doesn't.

from the mdn :

using setattribute() modify attributes, notably value in xul, works inconsistently, attribute specifies default value. access or modify current values, should use properties. example, use elt.value instead of elt.setattribute('value', val).


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

c++ - End of file on pipe magic during open -