How to display value of radio button in button click event using jQuery?
Are you new user to jQuery? Then this code snippet will be useful for you. I have provided a very basic jQuery script for obtaining the value of a radio button which the user has selected on the click of submit button.
jQuery is a very lightweight library with the help of it you do the simple selections of DOM elements on your page.
In this example I have shown how to display value of radio button in button click event using jQuery.
Add HTML page in your .Net application. Please make sure that jquery-1.4.1.js exists in your application else you can download it using internet.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Radio button Value</title>
<script src ="Scripts/jquery-1.4.1.js" type ="text/javascript">
</script>
<script type ="text/javascript">
$(document).ready(function () {
$("button").click(function () {
alert("Value is " + $("#rdoVal").val());
});
});
</script>
</head>
<body>
<p>Select this: <input type="radio" id="rdoVal" value="Radio button one" >Radio button one</p>
<button>Submit</button>
</body>
</html>
You can view this HTML page in browser or you can run .Net application to view the output. After clicking on Submit button, you will get value of alert as "Value is Radio button one" at run time.