Example : How to Select/Deselect a Radio button in html using Java Script code?
<!doctype html>
<html>
	<head>
		<meta charset="UTF-8">
		
		<script>		
		function selection1()
		{
			var x = document.getElementById('male');
			//const x = document.getElementById('male');
			x.checked = true;
		}
		
		function selection2()
		{
			var x = document.getElementById('male');
			//const x = document.getElementById('male');
			x.setAttribute('checked', '');
		}
		
		function unselect()
		{
			var x = document.getElementById('male');
			//const x = document.getElementById('male');
			x.removeAttribute('checked');
		}
		</script>		
	</head>

	<body>
		<input type="radio" id="male" name="gender">Male
		<input type="radio" id="female" name="gender">Female
		<input type="radio" id="other" name="gender">Other
		
		<input type="submit" onclick="selection2()" value="Male Select">
		<input type="submit" onclick="unselect()" value="Unselect">
	</body>
</html>

Loading


0 Comments

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.