Our website would like to use cookies to store information on your computer. You may delete and block all cookies from this site, but parts of the site will not work as a result. Find out more about how we use cookies.

Login or Register

Powered by
Powered by Novacaster
 
JavaScript 101
by Bruce Ure at 15:55 04/03/05 (Forum::Technical Advice::General)
I have found loads of info about how to get the value of a checkbox (or any object) when you pass it in to a function as an object, but nothing about how to get it from the name.
I have a function into which I am passing an int which represents the index of a series of controls called things like txtName1, chkBastard1, and so on, to which I want to do unspeakable things.

I want to get the value of chkBastard1 in my function. The following works if I pass it in as an object:

<input type='checkbox' onclick='javascript:DoStuff(this);'>

DoStuff(theCheckbox) {
alert(theCheckbox.checked);
}

But I want to be able to do this:

<input type='checkbox' onclick='javascript:DoStuff(1);'>

DoStuff(intIndex) {
alert(["chkBastard" + intIndex].checked);
}

Is it possible? It MUST be possible.

I will probably do my usual and find the solution 3 minutes from now on t'internet.

:bu:

<< Netatalk and the spinning beac... eBay spoof >>
View Comments (Flat Mode) Printer Version
JavaScript 101 Bruce Ure - 4/03
    Re: JavaScript 101 Bruce Ure - 4/03
       Re: JavaScript 101 Simon - 4/03