Reputation:
I've got a JavaScript running 2 ".getElementById('').style"
changes. Both work perfectly in FF, but the first one doesn't work in IE7.
Appreciate all help :)
First SourceCode:
function ingen() {
document.getElementById('merInfo1').style.display='none';
document.getElementById('merInfo2').style.display='none';
document.getElementById('merInfo3').style.display='none';
document.getElementById('merInfo4').style.display='none';
document.getElementById('merInfo5').style.display='none';
document.getElementById('merInfo6').style.display='none';
document.getElementById('merInfo7').style.display='none';
}
HTML:
<span class="enkeltSkjema" id="avtaleInput">
<select name="radio1" id="radio1">
<option value="1" onClick="ingen()">lorem</option>
<option value="2" onClick="some()">lorem</option>
<option value="3" onClick="other()">lorem</option>
<option value="4" onClick="func()">lorem</option>
<option value="5" onClick="tion()">lorem</option>
<option value="6" onClick="names()">lorem</option>
<option value="7" onClick="goes()">lorem</option>
<option value="8" onClick="here()">lorem</option>
</select>
</span>
<span class="enkeltSkjema" id="merInfo">
<span id="merInfo1" name="merInfo1"></span>
<span id="merInfo2" name="merInfo2"></span>
<span id="merInfo3" name="merInfo3"></span>
<span id="merInfo4" name="merInfo4"></span>
<span id="merInfo5" name="merInfo5"></span>
<span id="merInfo6" name="merInfo6"></span>
<span id="merInfo7" name="merInfo7"></span>
</span>
Second, works fine in IE:
function levAdresse() {
if (document.getElementById('egenLevAdr').checked == true) {
document.getElementById('levAdrBox').style.display='block';
}
else {
document.getElementById('levAdrBox').style.display='none';
}
}
HTML:
<div id="levAdrBox">
<div id="levAdr">Field
<span class="" id="levAdrInput"><input type="text" id="text12" name="text12" /></span>
</div>
<div class="" id="levPostSted"> field:*
<span class="" id="levPostStedInput">
<input type="text" id="text18" name="text18" />
<span class="" id="levPostNr">field:*
<span class="" id="levPostNrInput">
<input type="text" id="text17" name="text17" />
</span>
</span>
</span>
</div>
</div>
Upvotes: 1
Views: 4818
Reputation: 81
Uhhmmm... Maybe if you use "OnChange()" on the SELECT and not "OnClick" on OPTION ?
<select name="radio1" id="radio1" onChange="ingen(this.value)">
<option value="1">lorem</option>
<option value="2">lorem</option>
<option value="3">lorem</option>
<option value="4">lorem</option>
<option value="5">lorem</option>
<option value="6">lorem</option>
<option value="7">lorem</option>
<option value="8">lorem</option>
</select>
and in the ingen(something) do a condition, or call other function in relation with the value passed... ?
Upvotes: 4
Reputation: 63588
Do you have ANY other elements ANYWHERE else on the page with a "name" attribute set to:
merInfo1
merInfo2
merInfo3
merInfo4
merInfo5
merInfo6
merInfo7
(of any case too: e.g. MerInfo1, merinfo1, MERinfo1 are all the same in IE)
if so, that's the bug. IE considers name to be the same as ID (which is a bug obviously)
Upvotes: 2
Reputation: 9020
If you have the option/possibility, I'd use jQuery and get rid of (most of) the cross-browser incompatibilities:
function ingen() {
$("#merInfo span").css("display", "none");
}
$(document).ready(function() {
$("#egenLevAdr").click(function() { $("#levAdrBox").toggle(); });
});
Upvotes: 0
Reputation: 2044
Is it possible you are calling the ingen() function before the DOM is fully constructed?
Upvotes: 2