Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Adding Radio Button Values

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Coding Help needed

    HI i have a form with 2 radio buttons Male and Female. And i have multiple DIV.
    I need to hide the female div when the male radio button is clicked and hide the female div when the male radio button is clicked. i am unable to do this with multiple div. please help

    coding is as follows --->

    <html>
    <head>
    <title>Help me</title>

    <style type="text/css">
    .hide {display: none}
    </style>

    <script type="text/javascript">
    function hideDiv(){
    tag = document.getElementsByTagName("div");
    for(x=0;x<tag.length; x++){
    if(tag[x].getAttribute('id').indexOf("choose_") != -1){
    tag[x].style.display = "none";
    }
    }
    }
    function view(id){
    ge = document.getElementById('choose_' + id.value);
    hideDiv();
    ge.style.display = "block";
    }
    </script>

    </head>
    <body>
    <table>
    <form name="form1" id="form1" method="post" action="">
    <td>
    <tr><input type="radio" name="name1" value="a1" onclick="view(this)">Male </tr>
    <tr><input type="radio" name="name1" value="a2" onclick="view(this)">Female </tr>
    </td>
    <td>
    <tr><div class="hide" id="choose_a1">Hides Female Questions and shows Male questions</div></tr>
    <tr><div class="hide" id="choose_a1">Hides Female Questions and shows Male questions</div></tr>
    <tr><div class="hide" id="choose_a2">Hides Male Questions and shows Female questions</div></tr>
    <tr><div class="hide" id="choose_a2">Hides Male Questions and shows Female questions</div></tr>
    </td>


    </form>
    </table>
    </body>
    </html>


  2. #2
    Junior Member
    Join Date
    Nov 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Adding Radio Button Values

    Hi, I have been trying to find a solution or this for ages but have got one nowhere
    I want to add the value of the radio buttons for different questions and have it saved in a hidden textbox.
    is it possible ??

    here is the code

    <DIV class="quest" id="sec19">
    <TABLE width="20%">

    <TR class="question">
    <TD>1. Question one
    <TD align="right">
    <INPUT type="radio" name="Question one" id="sec191" value="0" onclick="add19(this.value)">
    <INPUT type="radio" name="Question one" id="sec191" value="2" onclick="add19(this.value)">
    <INPUT type="radio" name="Question one" id="sec191" value="5" onclick="add19(this.value)">
    <INPUT type="radio" name="Question one" id="sec191" value="10" onclick="add19(this.value)">
    <TR class="question">
    <TD>2. Question two
    <TD align="right">
    <B>&nbsp;No&nbsp;</B><INPUT type="radio" name="Question two" id="sec192" value="0" onclick="add19(this.value)">
    <B>&nbsp;Yes&nbsp;</B><INPUT type="radio" name="Question two" id="sec192" value="10" onclick="add19(this.value)">

    <TD align="right"><INPUT type="hidden" name="sectotal19" id="sectotal19" value="" class="textbox" maxlength="5" size="5">

    </TABLE>
    </DIV>

    <DIV class="quest" id="sec20">
    <TABLE width="20%">

    <TR class="question">
    <TD>1. Question three
    <TD align="right">
    <INPUT type="radio" name="Question three" id="sec201" value="0" onclick="add20(this.value)">
    <INPUT type="radio" name="Question three" id="sec201" value="2" onclick="add20(this.value)">
    <INPUT type="radio" name="Question three" id="sec201" value="5" onclick="add20(this.value)">
    <INPUT type="radio" name="Question three" id="sec201" value="10" onclick="add20(this.value)">
    <TR class="question">
    <TD>2. Question Four
    <TD align="right">
    <B>&nbsp;No&nbsp;</B><INPUT type="radio" name="Question Four" id="sec202" value="0" onclick="add20(this.value)">
    <B>&nbsp;Yes&nbsp;</B><INPUT type="radio" name="Question Four" id="sec202" value="10" onclick="add20(this.value)">

    <TD align="right"><INPUT type="hidden" name="sectotal20" id="sectotal20" value="" class="textbox" maxlength="5" size="5">

    </TABLE>
    </DIV>

  3. #3
    Member
    Join Date
    Oct 2010
    Posts
    40
    Thanks
    0
    Thanked 2 Times in 1 Post

    Default Re: Coding Help needed

    this is a java forum, i dont think they do javascript here, but ithink this is what your looking for.

    <html>
    <head>
    <title>Help me</title>
     
    <style type="text/css">
    .hide {display: none}
    </style>
     
    <script type="text/javascript">
    function hideDiv(){
    tag = document.getElementsByTagName("div");
    for(x=0;x<tag.length; x++){
    if(tag[x].getAttribute('id').indexOf("choose_") != -1){
    tag[x].style.display = "none";
    }
    }
    }
    function view(id){
    ge = document.getElementById('choose_' + id.value);
    hideDiv();
    ge.style.display = "block";
    	if(id.value=="a1"){
    		f = document.getElementById('F');
    		f.style.visibility = 'hidden';
    		f.style.color = 'white';
    	}
    		if(id.value=="a2"){
    		f = document.getElementById('M');
    		f.style.visibility = 'hidden';
    		f.style.color = 'white';
    	}
    }
    </script>
     
    </head>
    <body>
    <table>
    <form name="form1" id="form1" method="post" action="">
    <td>
    <tr><input id = "M" type="radio" name="name1" value="a1" onclick="view(this)">Male </tr>
    <tr><input id = "F" type="radio" name="name1" value="a2" onclick="view(this)">Female </tr>
    </td>
    <td>
    <tr><div class="hide" id="choose_a1">Hides Female Questions and shows Male questions</div></tr>
    <tr><div class="hide" id="choose_a1">Hides Female Questions and shows Male questions</div></tr>
    <tr><div class="hide" id="choose_a2">Hides Male Questions and shows Female questions</div></tr>
    <tr><div class="hide" id="choose_a2">Hides Male Questions and shows Female questions</div></tr>
    </td>
     
     
    </form>
    </table>
    </body>
    </html>

    Please use tags next time for code readability.

    Also u also have to do add some codes in there to make the labels for radio button disappear to.

  4. #4
    Junior Member
    Join Date
    Nov 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Coding Help needed

    Thanks for replying relixus but the code still does not solve the problem.
    It hides the other radio button.
    whereas we are looking at hiding the 2 female divs and showing the 2 male div on clicking the male radio button and vice versa for female.

  5. #5
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: Adding Radio Button Values

    You've already been told on your other thread
    this is a java forum, i dont think they do javascript here
    Now please find a JavaScript forum and stop posting off topic questions here.

    db

  6. #6
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Adding Radio Button Values

    Try JavaScript - SitePoint Forums

    I'm sure they will be able to help you there.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  7. #7
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: Adding Radio Button Values

    There's also a forum link on the oh-so-obvious JavaScript.com (TM) - The Definitive JavaScript Resource: JavaScript Tutorials, Free Java Scripts, Source Code and Other Scripting Resources

    db

Similar Threads

  1. Adding fixed size picture and button to panel
    By Javabeginner in forum AWT / Java Swing
    Replies: 10
    Last Post: August 23rd, 2010, 06:07 PM
  2. Action from Radio Button
    By halfwaygone in forum What's Wrong With My Code?
    Replies: 0
    Last Post: April 25th, 2010, 10:52 AM
  3. [SOLVED] Maps and adding to sets as values
    By mds1256 in forum Collections and Generics
    Replies: 3
    Last Post: March 26th, 2010, 09:12 AM
  4. radio buttons stop working
    By tabutcher in forum AWT / Java Swing
    Replies: 2
    Last Post: March 5th, 2010, 09:28 AM
  5. [SOLVED] Using html Radio Buttons with Servlets
    By oss_2008 in forum Java Servlet
    Replies: 2
    Last Post: June 25th, 2009, 05:39 AM

Tags for this Thread