AW: AW: AW: [Javascript] checkboxes in array
Michael Borchers
borchers at tridem.de
Mon Apr 4 09:31:00 CDT 2005
>>>
>
> <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
<<<
you got me;) php, indeed!
i'm in a hurry,
how would you solve this problem,
could you post a form?
about the script:
a php script creates a loop with input fields.
the first one is the checkbox with the value, f.e. a car type
the second text input shows the amount of cars available
when someone focusses the text input, the checkbox of the desired car is checked.
that's it;)
thanks!
see you tomorrow
More information about the Javascript
mailing list