Solved

Simple JavaScript Hide/Show DIV Question

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

821 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