JavaScript Show/Hide

Hi Experts,
I would like to add two more radio buttons so that I can display 333 and 444 when they are clicked.

Thanks for your help

<script type="text/javascript">
	function showHide(id,toShow){
		$(id).style.display = toShow;
	function $(id){
		return document.getElementById(id);
	function removeNameIfParentDivHidden() {
		var divs = document.getElementsByTagName("div");
		for(var i=0;i<divs.length;i++) {
			if(divs[i].style.display == "none") {
				var e = divs[i].getElementsByTagName("*");
				for(var j=0;j<e.length;j++) {
					if(e[j].name && e[j].name.length>0) {

						e[j].name = "";
<br />

<input type="radio" name="SearchArea" onclick="showHide('111','block');showHide('222','none');">
<input type="radio" name="SearchArea" onclick="showHide('111','none');showHide('222','block');">

<div align="center" id="111" style="display: none">111</div>
<div align="center" id="222" style="display: none">222</div>
<div align="center" id="333" style="display: none">333</div>
<div align="center" id="444" style="display: none">444</div>


Open in new window

romsomIT DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rainer JeschorCommented:

without using jQuery library, here a little generic approach:
// List of div ids - used in the for loop
var divIds = ['111','222','333','444'];
function showHide(id){
    var displayStyle = "";
    // Loop through all ids
   	for(var i=0;i<divIds.length;i++) {
        // If it is the div to show?
        if (id === divIds[i]) {
            // Set the display style
            displayStyle = "block";
        } else {
            // Otherwise hide
            displayStyle = "none";
        // Change the display property accordingly
		$(divIds[i]).style.display = displayStyle;
// Helper function
function $(id){
    return document.getElementById(id);

Open in new window

Live sample:


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
romsomIT DeveloperAuthor Commented:
Thank you very much for your quick response. This is perfect!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.