469,623 Members | 1,929 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,623 developers. It's quick & easy.

hide / show div javascript is working in firefox but not IE

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
----------------------------
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script language=javascript type='text/javascript'>
Expand|Select|Wrap|Line Numbers
  1. function hidediv() {
  2.     if (document.getElementById) { // DOM3 = IE5, NS6
  3.         document.getElementById('genre_select1').style.visibility = 'hidden';
  4.     }
  5.     else {
  6.         if (document.layers) { // Netscape 4
  7.             document.genre_select1.visibility = 'hidden';
  8.         }
  9.         else { // IE 4
  10.             document.all.genre_select1.style.visibility = 'hidden';
  11.         }
  12.     }
  13. }
  14.  
  15. function showdiv() {
  16.     if (document.getElementById) { // DOM3 = IE5, NS6
  17.         document.getElementById('genre_select1').style.visibility = 'visible';
  18.     }
  19.     else {
  20.         if (document.layers) { // Netscape 4
  21.             document.genre_select1.visibility = 'visible';
  22.         }
  23.         else { // IE 4
  24.             document.all.genre_select1.style.visibility = 'visible';
  25.         }
  26.     }
  27. }
Expand|Select|Wrap|Line Numbers
  1. </script> 
  2.  
  3. </head>
  4. <body onload="javascript:hidediv()">
  5.       <form name="form" action="chart.php" method="post">
  6.         <select name="view_by">
  7.           <option value="" onclick="hide()">-----Chart view-----</option>
  8.            <option onclick="javascript:hidediv()">Most votes</option>
  9.           <option  onclick="javascript:hidediv()">Latest entries</option>
  10.           <option  onclick="javascript:hidediv()">Most profile views</option>
  11.  
  12.           <option  onclick="javascript:hidediv()">Age</option>
  13.           <option onclick="javascript:showdiv()">Genre</option>
  14.  
  15.           <option  onclick="javascript:hidediv()">User name a-z</option>
  16.           <option  onclick="javascript:hidediv()">------------------</option>
  17.          <option  onclick="javascript:hidediv()">Non competition entries</option>
  18.         </select>
  19.  
  20.         </select>  <input type="submit"  class="button"  value="Go" />
  21.         <br/>
  22.         <div id="genre_select1"><select name="genre_select">
  23.         <option value='1'>1</option><option value='2'>2</option> </select></div>
  24. </form>
  25. </div>
  26. </body>
  27. </html>
Sep 12 '07 #1
3 7516
epots9
1,351 Expert 1GB
what is your doctype? you forgot to state what doctype you want to use at the top of your html.

By not declaring a doctype ie acts even worst.
Sep 12 '07 #2
pbmods
5,821 Expert 4TB
Heya, Safiratec. Welcome to TSDN!

Please use CODE tags when posting source code:

[CODE=javascript]
JavaScript code goes here.
[/CODE]
Sep 12 '07 #3
acoder
16,027 Expert Mod 8TB
IE does not support onclick for option elements. Use the select element's onchange event handler instead.
Sep 13 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

19 posts views Thread by dmiller23462 | last post: by
2 posts views Thread by MOHSEN KASHANI | last post: by
3 posts views Thread by alex | last post: by
4 posts views Thread by bridgemanusa | last post: by
11 posts views Thread by jimstruckster | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.