473,587 Members | 2,580 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

1 New Member
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="javascr ipt: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 7764
epots9
1,351 Recognized Expert Top Contributor
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 Recognized Expert Expert
Heya, Safiratec. Welcome to TSDN!

Please use CODE tags when posting source code:

[CODE=javascrip t]
JavaScript code goes here.
[/CODE]
Sep 12 '07 #3
acoder
16,027 Recognized Expert Moderator MVP
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
3197
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 layer behind the menus. The closer div has a lower index than the submenu divs so it appears behind them. The closer div contains a transparent gif...
19
6871
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 JavaScript in this code from a couple different sites but I'm not 100% sure what each line is doing...This is the ASP code that I'm using for the...
2
12181
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 { display: none; }
3
2939
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 it's easy to get something wrong. If the browser does not support the required features, I want it to generate a completely static page with the...
4
4217
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 I would really like to use linked images instead to do the following: - When open.gif is clicked, the contents of the div show and open.gif is...
11
8012
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 display. If they put a value in the text box in the second row then display the third row etc. etc. etc. to 10 rows. I'm pretty new to javascript,...
18
4844
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 starting divs on my page, each one expanding onclick. The show/hide elemant works fine. There is one slight problem... I want the user to be able to...
0
2583
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 actionscript that is working flawlessly in Firefox/PC, Firefox/Mac, Safari/PC, and Safari/Mac but not ie6 or 7. They both have the same issue. They will...
3
3346
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... using java and external css to show/hide items on the same click. I found a script that uses the getElementById function to adjust the display style of a...
0
7918
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7843
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7967
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6621
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5392
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3875
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2353
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.