I am trying to load options to drop-down list depending on the selection made on other drop-down list. I have written a code which works on almost all major browsers, FF, Opera, Safari but doesn't work in IE7.
Here is my Javascript code:
<script type = "text/javascript">
var txt1 = "<option>state1<\/option><option>state2<\/option><option>state3<\/option><option>state4<\/option>";
var txt2 = "<option>stateA<\/option><option>stateB<\/option><option>stateC<\/option><option>stateD<\/option><option>stateE<\/option>";
function states_val() {
if(document.getElementById("country").options[0].selected==true) {
document.getElementById("states").disabled=true;
document.getElementById("states").innerHTML="<option>Select country<\/option>";
}
else if(document.getElementById("country").options[1].selected==true) {
document.getElementById("states").disabled=false;
document.getElementById("states").innerHTML=txt1;
}
else if(document.getElementById("country").options[2].selected==true) {
document.getElementById("states").disabled=false;
document.getElementById("states").innerHTML=txt2;
}
}
</script>
And HTML Code:
<select id="country" name="name_country" onchange="states_val()">
<option>select</option>
<option>country1</option>
<option>country2</option>
</select>
<select id="states" name="name_states"></select>
I am bound with Client-side scripting and have to simulate this using Javascript only. please help me debugging the code.