/    Sign up×
Community /Pin to ProfileBookmark

hide / show div not working in IE (working in Firefox)

Hi,

I want to show a div depending of the value of a <select> option, using 2 functions hidediv() and showdiv() – it is working fine in firefox, but not in IE (tested with IE 6 and 7). <body onload=”javascript:hidediv()”> DOES work in IE, but the rest does not.
Any ideas?
Thanks a lot

Tim

here is the code
—————————-

<html>
<head>
<script language=javascript type=’text/javascript’>
function hidediv() {
if (document.getElementById) { // DOM3 = IE5, NS6
document.getElementById(‘genre_select1’).style.vis ibility = ‘hidden’;
}
else {
if (document.layers) { // Netscape 4
document.genre_select1.visibility = ‘hidden’;
}
else { // IE 4
document.all.genre_select1.style.visibility = ‘hidden’;
}
}
}

function showdiv() {
if (document.getElementById) { // DOM3 = IE5, NS6
document.getElementById(‘genre_select1’).style.vis ibility = ‘visible’;
}
else {
if (document.layers) { // Netscape 4
document.genre_select1.visibility = ‘visible’;
}
else { // IE 4
document.all.genre_select1.style.visibility = ‘visible’;
}
}
}
</script>

</head>
<body onload=”javascript:hidediv()”>
<form name=”form” action=”chart.php” method=”post”>
<select name=”view_by”>
<option value=”” onclick=”hide()”>—–Chart view—–</option>
<option onclick=”javascript:hidediv()”>Most votes</option>
<option onclick=”javascript:hidediv()”>Latest entries</option>
<option onclick=”javascript:hidediv()”>Most profile views</option>

<option onclick=”javascript:hidediv()”>Age</option>
<option onclick=”javascript:showdiv()”>Genre</option>

<option onclick=”javascript:hidediv()”>User name a-z</option>
<option onclick=”javascript:hidediv()”>——————</option>
<option onclick=”javascript:hidediv()”>Non competition entries</option>
</select>

</select> <input type=”submit” class=”button” value=”Go” />
<br/>
<div id=”genre_select1″><select name=”genre_select”>
<option value=’1′>1</option><option value=’2′>2</option> </select></div>
</form>
</div>
</body>
</html>

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@FangSep 12.2007 — onclick on an option does not work in IE, use onchange for the select.
×

Success!

Help @safiratec spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...