?
Solved

How do you determine which radio is checked?

Posted on 2004-08-25
3
Medium Priority
?
494 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 10

Accepted Solution

by:
Bustarooms earned 1600 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 400 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

719 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