473,320 Members | 1,953 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,320 software developers and data experts.

Show / Hide Div Multiple Div's

1
Let me start by saying I'm a noob to JavaScript.

What I'm trying to do for my website is have a select menu that shows the number of div's that's selected. I found a JS that I could do that with, but it only toggles, not change specifically what's selected. So if you click the wrong one, it doesn't work right. Here's what I got:
Expand|Select|Wrap|Line Numbers
  1. <body>
  2.   <script type="text/javascript">
  3. function toggle_visibility(){
  4.     for(var i = 0,len = arguments.length;i < len; i++){
  5.     var e = document.getElementById(arguments[i]).style,d = e.display;
  6.     e.display = (d == "block") ? "none" : "block";
  7.   }
  8. }
  9. </script>
  10.  
  11.   <select name="select" id="select">
  12.     <option>0</option>
  13.     <option onclick="toggle_visibility('1');" >1</option>
  14.     <option onclick="toggle_visibility('1','2');">2</option>
  15.     <option onclick="toggle_visibility('1','2','3');">3</option>
  16.     <option onclick="toggle_visibility('1','2','3','4');">4</option>
  17.   </select><br>
  18. <div id="1" style="display: none;">Test1</div>
  19. <div id="2" style="display: none;">Test2</div>
  20. <div id="3" style="display: none;">Test3</div>
  21. <div id="4" style="display: none;">Test4</div>
  22. </body>
Any help would be appreciated, cause I'm lost.
Jun 22 '10 #1
1 3749
johny10151981
1,059 1GB
Expand|Select|Wrap|Line Numbers
  1. e.display = (d == "block") ? "none" : "block";
change the above line to simple
e.display="inline" or whatever

and before your for loop add another loop that will hide all the div. I think your problem will be solved.
And If I understand what you want, Then I am sure this is not a smart solution at all.
Jun 23 '10 #2

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

Similar topics

3
by: KathyB | last post by:
Hi, totally new to the div show/hide thing. I have some rows in a table. When I first load the page, I only want to see divs where the divID=ForView. When I load now, I see BOTH rows...even...
5
by: Steve | last post by:
Visual Studio 2003 C# Windows: I have a tree view control as my main menu control down the left side of my application. This has 2 Parent Nodes on it (Jobs and Employees). beneath these 2 main...
4
by: itunes66 | last post by:
how can i do this i already have a function to show/hide elements with one link but how can i show/hide multiple elements here is the script function obj_ref(object) { if...
1
by: Chris Kettenbach | last post by:
Good morning all, Any ideas for an easy function to show/hide a DIV element? I have two drop down lists on a page. I have two div elements I want to show and hide. If you select "other" in...
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...
2
by: Eero Tuomenoksa | last post by:
Hi Does someone knows how i can show/hide multible divs at one click? -- Käytössä Operan vallankumouksellinen sähköpostiohjelma: http://www.opera.com/mail/
1
by: billyudi | last post by:
I followed this post to use a form drop down to show/hide divs. http://www.thescripts.com/forum/thread150206.html Now I need to be able to show two or three divs at once while hiding all the...
2
by: vcuankitdotnet | last post by:
I have one .aspx page that contains multiple user controls. Based on the form requested, I would like to loop through all of the user controls on the page and display the one requested by using the...
1
by: Joshua | last post by:
I would like to show and hide multiple DIV's on a page. I would like them to be centered and in the same place (so i can have a div of info for each tab). I'm testing on firefox and I'm not able...
1
by: Window Frog | last post by:
Hello all, I am going to be utilizing a <divon a site that is shown and hidden w/ the click of a button. I can already do this, but when the button is clicked the <divis show quite rapidly. I'd...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.