Made this nice little loop for hiding and showing div’s, works as a charm in firefox and opera, but IE, safari and chrome say’s no….
So my question is; why?
function theme(nr){
document.getElementById(nr).style.display = "block";
for (i = 0;i <= 28; i++) {
if (i != nr) {
document.getElementById(i).style.display = "none";
}
}
}
HTML:
<select id="subject" name="subject">
<option value="no" selected>Velg tema</option>
<option value="value0" onChange="javascript:theme(0)" onClick="javascript:theme(0)" onFocus="javascript:theme(0)">value0</option>
<option value="value1" onClick="theme(1)">value1</option>
</select>
<div class="tips" id="theme_0" name="theme_0">
<div class="tipsLabel">Tips:</div>
<div class="tipsContent">
lorem ipsum
</div>
<div class="tips" id="theme_1" name="theme_1">
<div class="tipsLabel">Tips:</div>
<div class="tipsContent">
more lorem ipsum
</div>
and so on…
Thanx:)
You cannot use id s like this. Id should not start with a number.
Change your code to something like this. Append a string in front of the numbers for the elements.
From Basic HTML data types
Edit
Assign the change event handler to the select instead of option.
Sample using jquery
Working Demo