Solved

Need help with radio group buttons show/hide div layer...

Posted on 2011-09-13
3
440 Views
Last Modified: 2012-05-12
Hello,

I have four radio buttons in one group. Basically I need help with hiding div layer "my_box" initially and if the user selects radio buttons 2,3 or 4 then show the my_box div. If the user selects the 1st radio button then hide the "my_box" div.

I got it working initially but can't seem to get back to where it was working again plus I want to see if somebody else has a different way of coding it.

Thank you,

Brian
<form id="form1" name="form1" method="post" action="">
  <p>
    <label>
      <input type="radio" name="RadioGroup1" value="radio" id="RadioGroup1_0" />
      Radio</label>
1    <br />
    <label>
      <input type="radio" name="RadioGroup1" value="radio" id="RadioGroup1_1" />
      Radio 2</label>
    <br />
    <label>
      <input type="radio" name="RadioGroup1" value="radio" id="RadioGroup1_2" />
      Radio 3</label>
    <br />
    <label>
      <input type="radio" name="RadioGroup1" value="radio" id="RadioGroup1_3" />
      Radio</label>
4    <br />
  </p>
</form>

<div id="my_box" style="display: none;">
	Stuff...
</div>

Open in new window

0
Comment
Question by:brihol44
[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
3 Comments
 
LVL 38

Accepted Solution

by:
Tom Beck earned 125 total points
ID: 36530555

<form id="form1" name="form1" method="post" action="">
  <p>
    <label>
      <input type="radio" name="RadioGroup1" value="radio1" id="RadioGroup1_0" onclick="showHide(this)" />
      Radio</label>
1    <br />
    <label>
      <input type="radio" name="RadioGroup1" value="radio2" id="RadioGroup1_1" onclick="showHide(this)" />
      Radio 2</label>
    <br />
    <label>
      <input type="radio" name="RadioGroup1" value="radio3" id="RadioGroup1_2" onclick="showHide(this)" />
      Radio 3</label>
    <br />
    <label>
      <input type="radio" name="RadioGroup1" value="radio4" id="RadioGroup1_3" onclick="showHide(this)" />
      Radio</label>
4    <br />
  </p>
</form>

<div id="my_box" style="display: none;">
	Stuff...
</div>
<script type="text/javascript" language="javascript">
function showHide(obj) {
    switch (obj.value) {
        case "radio2" : case "radio3" : case "radio4" :
         document.getElementById('my_box').style.display = 'block';
         break;
        default:
         document.getElementById('my_box').style.display = 'none';
    }
}

</script>

Open in new window

0
 
LVL 82

Expert Comment

by:leakim971
ID: 36530734
With jQuery : http://jsfiddle.net/cSHfm/

$(document).ready(function() {
    $("input[name='RadioGroup1']").change(function() {
        if( $(this).attr("id") == "RadioGroup1_0" && $(this).is(":checked") ) {
            $("#my_box").hide();
        }
        else {
            $("#my_box").show();
        }
    })
})

Open in new window

0
 

Author Closing Comment

by:brihol44
ID: 36530773
Thx!

Brian
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

705 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