Closed Thread
Results 1 to 6 of 6

Thread: Display Radio Button Value onclick

  1. #1
    Barn Newbie theChris is an unknown quantity at this point theChris's Avatar
    Join Date
    Mar 2008
    Posts
    14
    Rep Power
    4

    Display Radio Button Value onclick

    Hi,

    Is there easy way to dispaly the value of a radio button when it is clicked?

    Thanks,

    theChris
    Last edited by richyrich; May 6th, 2008 at 12:58 PM. Reason: Removed [SOLVED] from title

  2. #2
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    You can have such code:

    Code:
    <script language="javascript" type="text/javascript">
    <!--
    function displayValue()
    {
     for (var i = 0; i < document.form1.radiobut.length; i++)
       {
        if (document.form1.radiobut[i].checked)
         {    
          var display = document.form1.radiobut[i].value;
          alert(display);
          
         }
       }
    }
    //-->
    </script>
    
    Above, replace "form1" and "radiobut" with the names of your form and radiobutton.
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  3. #3
    Moderator don94403 is a jewel in the rough don94403 is a jewel in the rough don94403 is a jewel in the rough don94403's Avatar
    Join Date
    Mar 2008
    Location
    San Mateo, CA, USA
    Posts
    313
    Blog Entries
    8
    Real Name
    Don Ravey
    Rep Power
    6

    Quote Originally Posted by theChris View Post
    Hi,

    Is there easy way to dispaly the value of a radio button when it is clicked?

    Thanks,

    theChris
    Not quite sure what you want to do--display something to the user when he/she selects one choice among several? Would this be to confirm that the choice has been made? Usually just the black dot in the option selected is taken as the indication that the choice has been made. Or am I missing your point?

  4. #4
    Barn Newbie theChris is an unknown quantity at this point theChris's Avatar
    Join Date
    Mar 2008
    Posts
    14
    Rep Power
    4

    Quote Originally Posted by don94403 View Post
    Not quite sure what you want to do--display something to the user when he/she selects one choice among several? Would this be to confirm that the choice has been made? Usually just the black dot in the option selected is taken as the indication that the choice has been made. Or am I missing your point?
    It's simply for troubleshooting purposes, I just want to see if there is an easy way using JavaScript to display the value of the selected radiobutton.

  5. #5
    KIS keep_it_simple is on a distinguished road keep_it_simple's Avatar
    Join Date
    Mar 2008
    Posts
    5
    Rep Power
    4

    Quote Originally Posted by theChris View Post
    It's simply for troubleshooting purposes, I just want to see if there is an easy way using JavaScript to display the value of the selected radiobutton.

    yes...if simply wanting to debug then you can use inline code

    HTML Code:
    <html>
     <head>
      <title>Javascript onclick Radio Button Demo</title>
     </head>
     <body>
      <form action="page.htm" method="post">
       <fieldset>
        <legend>Gender</legend>
         <table>
          <tr>
           <td>Male</td>
           <td><input type="radio" name="gender" value="Male" onclick="alert(this.value);"></td>
          </tr>
          <tr>
           <td>Female</td>
           <td><input type="radio" name="gender" value="Female" onclick="alert(this.value);"></td>
          </tr>
         </table>
       </fieldset>
      </form>
     </body>
    </html> 

  6. #6
    Barn Newbie theChris is an unknown quantity at this point theChris's Avatar
    Join Date
    Mar 2008
    Posts
    14
    Rep Power
    4

    Thanks guys, both solutions worked

Closed Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO