Solved

How do you determine which radio is checked?

Posted on 2004-08-25
3
484 Views
Last Modified: 2008-02-01
How do you determine which radio is checked using Javascript, so I can change target on submit?

<form>
<input type=checkbox name=chk value=1>Send to 1
<input type=checkbox name=chk value=2>Send to 2
</form>
0
Comment
Question by:golfDoctor
3 Comments
 
LVL 10

Accepted Solution

by:
Bustarooms earned 400 total points
ID: 11896231
if(document.yourFormName.chk[0].checked) alert('Send to 1 is checked');
else alert('Send to 2 is checked');
0
 
LVL 5

Assisted Solution

by:darksinclair
darksinclair earned 100 total points
ID: 11896305
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.");
0
 
LVL 16

Author Comment

by:golfDoctor
ID: 11896340
Thanks.  Both have helped in my understanding...
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now