Register Blogs FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read

Go Back   DeveloperBarn Forums > Programming & Scripting > JavaScript Programming

Sponsored Links

Discuss "Display Radio Button Value onclick" in the JavaScript Programming forum.

JavaScript Programming - Javascript is a cross-browser client-side scripting language. Discuss Javascript and AJAX related scripts here.


Closed Thread
 
LinkBack Thread Tools Display Modes
  #1  
Old March 21st, 2008, 11:33 AM
Barn Newbie
 
Join Date: Mar 2008
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Power: 1
theChris is an unknown quantity at this point
Default 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 11:58 AM. Reason: Removed [SOLVED] from title
Sponsored Links
  #2  
Old March 21st, 2008, 11:36 AM
jmurrayhead's Avatar
The Barnfather
 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 949
Thanks: 22
Thanked 93 Times in 90 Posts
Blog Entries: 6
Rep Power: 4
jmurrayhead is a jewel in the roughjmurrayhead is a jewel in the roughjmurrayhead is a jewel in the roughjmurrayhead is a jewel in the rough

Awards Showcase
Microsoft Windows Microsoft SQL Server Microsoft .Net Classic ASP 
Total Awards: 4

Default

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 with me... click the icon!
If my post solved your problem, click the button in the lower right-hand corner of the post.

If you like it here...throw us a few bones to help
support us.

Join our Folding team: DeveloperBarn Folding

  #3  
Old March 21st, 2008, 12:57 PM
don94403's Avatar
Moderator
 
Join Date: Mar 2008
Location: San Mateo, CA, USA
Posts: 69
Thanks: 3
Thanked 12 Times in 10 Posts
Blog Entries: 7
Rep Power: 1
don94403 will become famous soon enough

Awards Showcase
Microsoft Access PHP 
Total Awards: 2

Default

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  
Old March 21st, 2008, 01:00 PM
Barn Newbie
 
Join Date: Mar 2008
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Power: 1
theChris is an unknown quantity at this point
Default

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  
Old March 22nd, 2008, 11:20 AM
keep_it_simple's Avatar
KIS
 
Join Date: Mar 2008
Posts: 5
Thanks: 0
Thanked 1 Time in 1 Post
Rep Power: 1
keep_it_simple is on a distinguished road

Awards Showcase
Classic ASP 
Total Awards: 1

Default

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> 

Comments on this post
theChris agrees:
  #6  
Old March 22nd, 2008, 02:28 PM
Barn Newbie
 
Join Date: Mar 2008
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Power: 1
theChris is an unknown quantity at this point
Default

Thanks guys, both solutions worked
Closed Thread

  DeveloperBarn Forums > Programming & Scripting > JavaScript Programming

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -4. The time now is 01:30 PM.



Content Relevant URLs by vBSEO 3.2.0