Home > Web Front-end > HTML Tutorial > How to pass the selected value in radio to javascript? _html/css_WEB-ITnose

How to pass the selected value in radio to javascript? _html/css_WEB-ITnose

WBOY
Release: 2016-06-24 12:10:05
Original
1201 people have browsed it

<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>
Copy after login


I want the value of the radio I selected to be displayed after the button is clicked


Reply to discussion (solution)

<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>
Copy after login

jquery code




< ;title> New Document







1


2










I am a newbie, don’t shoot me! ! Hehe

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template