• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 497
  • Last Modified:

How do you determine which radio is checked?

How do you determine which radio is checked using Javascript, so I can change target on submit?

<input type=checkbox name=chk value=1>Send to 1
<input type=checkbox name=chk value=2>Send to 2
2 Solutions
if(document.yourFormName.chk[0].checked) alert('Send to 1 is checked');
else alert('Send to 2 is checked');
Good solution bustarooms but what if he has many?

for( i = 0; i < document.yourFormName.elements.length; i++ )
var found = false;

if( document.yourFormName.elements[i].type == "radio" && document.yourFormName.elements[i].checked )
   alert( document.yourFormName.elements[i].name );
   found = true;

if( !found )
   alert("No Radio buttons were checked.");
golfDoctorAuthor Commented:
Thanks.  Both have helped in my understanding...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now