Check differently named checkboxes

J

jamesboulter

Dear all,

I can find plenty of functions that check all checkboxes with a certain
HTML "name" attribute, but on the page in question, each is named
slightly differently:

Therapy_1
Therapy_2
Therapy_3
etc.

Perhaps someone could advise how the increasing number could be
incorporated into the Javascript and hence each of the boxes be ticked?

Many thanks in advance,
James Boulter
 
M

Matt Kruse

I can find plenty of functions that check all checkboxes with a
certain HTML "name" attribute, but on the page in question, each is
named slightly differently:
Therapy_1
Therapy_2
Therapy_3

Check out my "Checkbox Group" library at:
http://www.javascripttoolbox.com/checkboxgroup/

It allows you to group boxes together using wild cards, such as "Therapy_*"
under a master control box.

Otherwise, you can manually loop through all form inputs and check their
name with:
if (obj.name.indexOf("Therapy_")==0) { obj.checked=true; }
 
J

jamesboulter

Thanks Matt, that's a great solution - now using your script!
Being very ignorant of Javascript, I'd missed the "*" solution!

Cheers,
James
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top