473,391 Members | 1,426 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,391 software developers and data experts.

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 7743
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

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

Similar topics

10
by: David | last post by:
Hi everyone, Hoping there are some .js/browser experts out there that can help with this weird problem. I have made a swap div routine and applied the events to menu buttons with a closer...
19
by: dmiller23462 | last post by:
Hi guys....I have absolutely NO IDEA what I'm doing with Javascript but my end result is I need two text boxes to stay hidden until a particular option is selected....I've cobbled together the...
2
by: MOHSEN KASHANI | last post by:
Hi, I am trying to hide some form elements in a form by default and show/hide depending on which radio button is clicked. This is what I have but it is not working: <head> <style> ..noshow {...
3
by: alex | last post by:
I'd like to have a show/hide widget on my web site, kind of like "show details" / "hide details" in Google Groups. Is there a tutorial explaining how to make them? Google's is a bit complex and...
4
by: bridgemanusa | last post by:
Hi All: I have a very long page of html that I want to take portions and hide them in divs, then show when a link is clicked. I have the hide show part working when the link is clicked, however...
11
by: jimstruckster | last post by:
I have a table with 10 rows, I want all rows except for the first to be hidden when the page first opens up. If the user puts a value in a text box in the first row then I want the second row to...
18
by: ryrocks | last post by:
Hi, Im making a 'contact us' page. The user click on the div, this then reveals another larger div displaying more information giving the effect of the box expanding or dropping down. I have 3...
0
techtherapy
by: techtherapy | last post by:
Hello All! This ones a little different as I'm using flash actionscripting to control some javascript swaping. The following page uses a hideDiv, ShowDiv Javascript and the following...
3
by: timplx | last post by:
Hello all, New to javascript and have never worked with programming languages like c++, so my logic in some of these statements might be incorrect or redundant Got a problem with my page......
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.