Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get the names of all the Controls in a form of type Checkbox 1

Status
Not open for further replies.

vikaskalra

Technical User
Aug 12, 2002
41
GB
Hi,

I needed some help in identifying controls using JavaScript. Say I have a form, at runtime, depending on some selection criteria on the previous page, I generate certain number of Checkboxes, and place them all in a Form- ABC.

What I want to do is when the user Clicks on the Submit button, I want to get a list of the names of the Checkboxes the user has selected. Please note that the name of the Checkboxes are all variable. They can be anything cb_1, cb_20, sb_1, ed_30 etc.

So the output of the routine should be an alert, saying -You Checked cb_11, cb_21 etc.

Regards,
Vikas
 
function getChecked(f) {
message = "You Checked ";
for (n=0; n<f.elements.length; n++)
if (f.elements[n].type == &quot;checkbox&quot; && f.elements[n].checked)
message += f.elements[n].name + &quot;, &quot;;

alert(message);
}

<form ... onsubmit=&quot;getChecked(this)&quot;>
 
Thanks for the quick response, it is working fine !

Regards,

Vikas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top