Solved

Simple JavaScript Hide/Show DIV Question

Posted on 2010-08-19
3
359 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
Comment Utility
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
Comment Utility
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
Comment Utility
Great.  Sorry, I don't have my usual debugging system, so I was using Notepad. :)  Glad it's working!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
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…

744 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

13 Experts available now in Live!

Get 1:1 Help Now