简体   繁体   中英

Javascript not functioning with IE9

I have a dropdown whose list is dependent on what is selected in another dropdown. The dropdown is populated by javascript. It works correctly in Chrome and FF but not in IE, all I get is a blank dropdown.

Here is the relevant code: price and mileage are 2 js arrays that hold the required info

var serviceMileage='<select name=\'servicing\' id=\'servicing\''+ 
'onfocus=\'setStyle(this.id);\''+
'onblur=\'setStyleBack(this.id);\'>';

for (var i=0;i<mileage.length;i++)
{serviceMileage=serviceMileage+'<option value='+price[i]+'>'+mileage[i]+'</option>'}
serviceMileage=serviceMileage+'</select>';

document.getElementById('servicing').innerHTML=serviceMileage;

Any pointers gratefully received!

Try write in this way:

var serviceMileage="<select name='servicing' id='servicing' onfocus='setStyle(this.id); onblur='setStyleBack(this.id);'>";

for (var i=0;i<mileage.length;i++){
    serviceMileage=serviceMileage+"<option value='"+price[i]+"'>"+mileage[i]+"</option>"
}
serviceMileage=serviceMileage+'</select>';

document.getElementById('servicing').innerHTML=serviceMileage;

Your problem is here probably:

... value='+price[i]+' ...

it should be

... value='"+price[i]+"'...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM