Solved

How do you determine which radio is checked?

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Rotate images for Web Page 11 40
Open grouped links on a page in new tabs via jquery 5 61
Changing the format from a text box to a drop-down menu 9 37
Jquery syntax 12 30
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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

751 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