[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2011-09-13
3
Medium Priority
?
444 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 500 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

656 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