Solved

How do you determine which radio is checked?

Posted on 2004-08-25
3
493 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 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
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…
Suggested Courses

630 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