AW: AW: [Javascript] checkboxes in array
Roger Roelofs
rer at datacompusa.com
Mon Apr 4 08:51:10 CDT 2005
Michael,
On Apr 4, 2005, at 3:50 AM, Michael Borchers wrote:
>
> <input type="checkbox" name="typ[]" value="S06-001"
> style="border:none; ">
> <input type="text" name="stck[]" style="width:50px; " value="0"
> onFocus="this.value='';
> document.getElementsByName('typ[]').checked=true">
>
> I need to have it without certain IDs or names, just arrays []
I'm guessing you're coming from a server side language like php where
arrays use square brackets. Unfortunately javascript uses square
brackets too. To get around this use the forms elements array. Here
is a quote from the php web site
<http://us2.php.net/manual/en/faq.html.php#faq.html.arrays>
---------------------
Note that if you are using JavaScript the [] on the element name
might cause you problems when you try to refer to the element by name.
Use it's numerical form element ID instead, or enclose the variable
name in single quotes and use that as the index to the elements array,
for example:
variable = documents.forms[0].elements['var[]'];
---------------------
I guess the main point is you can't do it the old way of
document.formname.typ[] because javascript willl assume you are
referencing an array rather than a form element. Also, 'variable' will
be an array of form elements if more than one has the same name.
getElementsByName tends to be a bit buggy
<http://www.quirksmode.org/dom/w3c_core.html>, so it will only work for
input elements, and images.
hth,
Roger
-------------------------------------------------------
Roger Roelofs web www.datacompusa.com
Datacomp Appraisal Services Email rer at datacompusa.com
3215 Eaglecrest Drive, NE
Grand Rapids, MI 49525-4593
More information about the Javascript
mailing list