This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes how to print  a default selected radio button value if there is a single radio button ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "how to print  a default selected radio button value if there is a single radio button ?" Watch "how to print  a default selected radio button value if there is a single radio button ?" New topic
Author

how to print a default selected radio button value if there is a single radio button ?

shivamahesh bachu
Greenhorn

Joined: Sep 14, 2012
Posts: 13
Here is My Code:-

please help me out in this
I am unable to get the output here

<html>
<head>
<script type="text/javascript">


function get_radio_value()
{

for (var i=0; i < document.orderform.music.length; i++)
{
if (document.orderform.music[i].checked)
{
var rad_val = document.orderform.music[i].value;
alert("hai"+rad_val);
}
}
}


</script>
<form name="orderform">
Which one is your favorite?<br>
<input type="radio" name="music" value="Rock" checked="checked"> Rock<br>
<input type="submit" onclick="get_radio_value()">
</form>
</body>

</head>
</html>
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
When you post code, please you code tags.

Answer can be found on this old post: http://www.coderanch.com/t/115796/HTML-CSS-JavaScript/inconsistency-radiobutton

Eric
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to print a default selected radio button value if there is a single radio button ?
 
Similar Threads
Not able to retrive the Value sent through JavaScript function
radio button error problem?
setting a radio button
JSP page not showing alert box
Serverlet/JSP