Using function values in code

  • Thread starter susan.f.barrett
  • Start date
S

susan.f.barrett

Hi peeps

If I was passing in an name/ID of a checkbox to a function such as:

function disableChecks(thisForm, theseCheckboxes)
//thisForm is this.form
//theseCheckboxes is a checkbox

How do I access that checkbox? e.g.

if (thisForm.theseChecks.checked' == false) {
// do code
}

Obviously doesn't work, but I have no idea what to change it to.

Thanks for your time
Susan
 
R

RobG

Hi peeps

If I was passing in an name/ID of a checkbox to a function such as:

function disableChecks(thisForm, theseCheckboxes)
//thisForm is this.form
//theseCheckboxes is a checkbox

How do I access that checkbox? e.g.

if (thisForm.theseChecks.checked' == false) {
// do code
}

Obviously doesn't work, but I have no idea what to change it to.

How to reference DOM objects is addressed in the FAQ:

<URL:http://www.jibbering.com/faq/>


Briefly, if 'thisForm' is a reference to the form, and the value of
'theseCheckboxes' is a string that is the name of a checkbox in the
form, then:

var theCheckbox = thisForm[theseCheckboxes];

or

var theCheckbox = thisForm.elements[theseCheckboxes];


will set the value of theCheckbox to be a reference to the checkbox
whose name has been stored in 'theseCheckboxes'.

The difference between using dot notation and square brackets is
explained in the FAQ. Be aware that if more than one form control has
the same name as 'theseCheckboxes', then 'theCheckbox' will be a
reference to a collection of those elements - names do not have to be
unique.

In that case to access an individual checkbox you need to use indexes:

theCheckbox[0] is the first,
theCheckbox[1] is the second,
etc.
 

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

No members online now.

Forum statistics

Threads
473,781
Messages
2,569,615
Members
45,302
Latest member
endevsols

Latest Threads

Top