473,396 Members | 2,002 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,396 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 7744
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:
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.