Solved

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

Posted on 2011-09-13
3
439 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Can't get javascript video player button to work 10 23
Link not working 6 43
Jquery 7 34
javascript and jquery question 4 26
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

730 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