ADVERTISEMENT
ADVERTISEMENT

Check selected Radio Button value using JavaScript

In this code snippet we are checking gender using JavaScript function.

Check Selected Radio Button value

HTML and JavaScript:

<!--Check selected Radio Button value using JavaScript.-->

<html>
   <head>
      <title>Check selected Radio Button value using JavaScript.</title>
      <script type="text/javascript">
         function checkGender(){				
         	if(document.getElementById('radioMale').checked)
         		alert("You have selected Male.");
         	else
         		alert("You have selected Female.");
         }
      </script>
   </head>
   <body style="text-align: center;">
      <h1>Check selected Radio Button value using JavaScript.</h1>
      <b>Choose gender: </b><br><br>
      <input type="radio" id="radioMale" value="Male">Male</input>
      <input type="radio" id="radioFemale" value="Female">Female</input>
      <br><br>
      <input type="button" value="Check Gender" onClick="checkGender()"/>
   </body>
</html>

Result:

add two numbers using javascript

JavaScript Examples »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.