Home >Web Front-end >HTML Tutorial >How to pass the selected value in radio to javascript? _html/css_WEB-ITnose
<html xmlns="http://www.w3.org/1999/xhtml"><head> <title></title> <script type="text/javascript"> function che() { alert(); } </script></head><body><form name="rad" method="post" action="#"><div><p><input type="radio" value="1" name="r"/>1</p><p><input type="radio" value="2" name="r"/>2</p></div><input type="button" value="check" onclick="che()"/></form></body></html>
<html xmlns="http://www.w3.org/1999/xhtml"><head> <title></title> <script type="text/javascript"> function che() { var rs = document.getElementsByName('r'); for (var i = 0, len = rs.length; i < len; i++) { if (rs[i].checked) { alert(rs[i].value); break; } } } </script></head><body><form name="rad" method="post" action="#"><div><p><input type="radio" value="1" name="r"/>1</p><p><input type="radio" value="2" name="r"/>2</p></div><input type="button" value="check" onclick="che()"/></form></body></html>
jquery code
1a24b17f85e15c83fc29b7760e40bfcb
$("input[type=radio]").click(function() {
alert($(this).val());
});
2cacc6d41bbb37262a98f745aa00fbf0
82e4865872727f41d1edae4f463247d6
100db36a723c770d327fc0aef2ce13b1
93f0f5c25f18dab9d176bd4f6de5d30e
< ;title> New Document 6e916e0f7d1e588d4f442bf645aedb2f
97f2b6ae5f4f65bc7d15c6c9b9e8be8c
2840a3de185fface63704a94c15e7273
function che() {
var list = document.forms["rad"].elements("r");
for(var i=0;i
if(radio.checked){
alert(radio.value);
}
}
}
2cacc6d41bbb37262a98f745aa00fbf0
9c3bca370b5104690d9ef395f2c5f8d1
6c04bd5ca3fcae76e30b72ad730ca86d
c6d4ec18f90b8a5fa1bac7e07684f70c
dc6dce4a544fdca2df29d5ac0ea9906b
e388a4556c0f65e1904146cc1a846bee76441ed6d7ac7c0593e245bd01ddfbea194b3e26ee717c64999d7867364b1b4a3
e388a4556c0f65e1904146cc1a846beee185f7bf391826cb0bf5a9db933bbf60294b3e26ee717c64999d7867364b1b4a3
16b28748ea4df4d9c2150843fecfba68
ca2cd23246d56d26e75ff935264e8e2c
f5a47148e367a6035fd7a2faa965022e
36cc49f0c466276486e50c850b7e4956
73a6ac4ed44ffec12cee46588e518a5e
I am a newbie, don’t shoot me! ! Hehe