How to get value of a radio button in javascript

Code container, you can download it



<!DOCTYPE html>
<html lang="en">
<head>
<script>
function getValue(){
var data = document.getElementsByName("gender");
var i;
for(i=0; i<=data.length; i++){
	if(data[i].checked){
		document.getElementById("output").innerHTML=data[i].value;
}
}
}
</script>
</head>
<body>
<h3> How to get the Value of Radio Button</h3>
<label>Select your Gender</label>
<input type="radio" name="gender" value="Male"/>Male
<input type="radio" name="gender" value="Female"/>Female
<button onclick="getValue()">Submit</button>
<h4>Result</h4>
<p id="output"></body><html>

One thought on “How to get value of a radio button in javascript | Radio button value in JavaScript”
  1. I have recently started a site, the information you offer on this site has helped me greatly. Thank you for all of your time & work.

Leave a Reply

Your email address will not be published. Required fields are marked *