Solved

Simple JavaScript Hide/Show DIV Question

Posted on 2010-08-19
3
366 Views
Last Modified: 2012-06-27
I have 3 radio buttons.. When a radio button is selected, I want to show the correct DIV. If the choice "None" is selected, I want to hide the divs....


Basically it is not really working.



<script language="Javascript1.2">
	function showOptions(){

		var radioLength = document.populateTable.rdo_choice.length;
		var checkedOption = '';

		for(var i = 0; i < radioLength; i++) {
			if(document.populateTable.rdo_choice[i].checked) {
				checkedOption = document.populateTable.rdo_choice[i].value;
			}
		}

		if (checkedOption == "sales")
			document.getElementById('sales_div').style.display='block';
		else if (checkedOption == "clients")
			document.getElementById('clients_div').style.display='block';
		else
			document.getElementById('sales_div').style.display='none';
			document.getElementById('clients_div').style.display='none';
	}
</script>




<input type="radio" name="rdo_choice" value="None" style="border: none;" onClick="return showOptions()"> None &nbsp;&nbsp;|&nbsp;&nbsp;
<input type="radio" name="rdo_choice" value="clients" style="border: none;" onClick="return showOptions()"> Report Details By Client &nbsp;&nbsp;|&nbsp;&nbsp;
<input type="radio" name="rdo_choice" value="sales" style="border: none;" onClick="return showOptions()"> Report Details Salesperson &nbsp;&nbsp;|&nbsp;&nbsp;


<div id="clients_div" style="display:none">

Data Here...

</div>

<div id="sales_div" style="display:none">

Data here...

</div>

Open in new window

0
Comment
Question by:theideabulb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
ploftin earned 500 total points
ID: 33481498
How about like this:

function showOptions(){
		
		if (document.populateTable.rdo_choice[0].checked) {
			document.getElementById('sales_div').style.display='block';
		}
		else if (document.populateTable.rdo_choice[1].checked) {
			document.getElementById('clients_div').style.display='block';
		}
		else {
			document.getElementById('sales_div').style.display='none';
			document.getElementById('clients_div').style.display='none';
		}
	}

Open in new window

0
 

Author Closing Comment

by:theideabulb
ID: 33481520
Ok, i had to change it to this, but it worked...

function showOptions(){

            if (document.populateTable.rdo_choice[2].checked) {
                  document.getElementById('sales_div').style.display='block';
                  document.getElementById('clients_div').style.display='none';
            }
            else if (document.populateTable.rdo_choice[1].checked) {
                  document.getElementById('clients_div').style.display='block';
                  document.getElementById('sales_div').style.display='none';
            }
            else {
                  document.getElementById('sales_div').style.display='none';
                  document.getElementById('clients_div').style.display='none';
            }
      }
0
 
LVL 5

Expert Comment

by:ploftin
ID: 33481525
Great.  Sorry, I don't have my usual debugging system, so I was using Notepad. :)  Glad it's working!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question