show and hide divs based on radio button click

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Untitled Document</title>
        <script type="text/javascript">
            function show(str){
                document.getElementById('sh2').style.display = 'none';
                document.getElementById('sh1').style.display = 'block';
            }
            function show2(sign){
                document.getElementById('sh2').style.display = 'block';
                document.getElementById('sh1').style.display = 'none';
            }
        </script>
    </head>

    <body>
        <p>
            <input type="radio" name="r1" id="e1" onchange="show2()"/> I Am New User   
            <input type="radio" checked="checked" name="r1" onchange="show(this.value)"/> Existing Member
        </p>
        <div id="sh1">Hello There !!</div>
        <p> </p>
        <div id="sh2" style="display:none;">Hey Watz up !!</div>
    </body>
</html>

3.75
8
Jsonnull 80 points

                                    &lt;div align=&quot;center&quot;&gt;
  &lt;input type=&quot;radio&quot; name=&quot;name_radio1&quot; id=&quot;id_radio1&quot; value=&quot;value_radio1&quot;&gt;Radio1
  &lt;input type=&quot;radio&quot; name=&quot;name_radio1&Prime; id=&quot;id_radio2&quot; value=&quot;value_radio2&Prime;&gt;Radio2
&lt;/div&gt;
 &lt;br /&gt;
&lt;div align=&quot;center&quot; id=&quot;id_data&quot; style=&quot;border:5&Prime;&gt;
  &lt;div&gt;this is div 1&lt;/div&gt;
  &lt;div&gt;this is div 2&lt;/div&gt;
  &lt;div&gt;this is div 3&lt;/div&gt;
  &lt;div&gt;this is div 4&lt;/div&gt;
&lt;/div&gt;
&lt;script src=&quot;jquery.js&quot;&gt;&lt;/script&gt;
&lt;script&gt;
 $(document).ready(function() {
 // show the table as soon as the DOM is ready
 $(&quot;#id_data&quot;).show();
 // shows the table on clicking the noted link
  $(&quot;#id_radio1&quot;).click(function() {
   $(&quot;#id_data&quot;).show(&quot;slow&quot;);
  });
 // hides the table on clicking the noted link
   $(&quot;#id_radio2&quot;).click(function() {
   $(&quot;#id_data&quot;).hide(&quot;fast&quot;);
   });
 });

3.75 (8 Votes)
0
Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source