Hi,
Is there easy way to dispaly the value of a radio button when it is clicked?
Thanks,
theChris
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
You can have such code:
Above, replace "form1" and "radiobut" with the names of your form and radiobutton.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>
jmurrayhead
If you agree, give me rep.
If you like it here...throw us a few bones to help support us.
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?
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>
Thanks guys, both solutions worked![]()
Bookmarks