Solved

Simple JavaScript Hide/Show DIV Question

Posted on 2010-08-19
3
363 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
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
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-…
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…

815 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now