[Javascript] access form.element by name containing [ ]

Rodney Myers rodney at aflyingstart.net
Tue Sep 18 05:48:44 CDT 2001


<input type="text"   name="action[upd]" value="abcd">
<input type="button" name="b1" value="ALERT TEST"
onclick="alert(this.form['action[upd]'].value)">

<input type="checkbox" name="action[new]" value="wxyz">
<input type="button" name="b1" value="CLICK TEST"
onclick="this.form['action[new]'].click()">

This worked in Win98 NN4.7 and MSIE 5.5
(in my test file crazy.htm<g>)

Rodney


Patrick Bierans wrote:

> "access form.element by name containing [ ]"
>
> Hello out there.
>
> I use checkboxes named "action[new]", "action[del]" and
> "action[upd]". I have to do it this way because it produces
> arrays in PHP making it much (!) easier for me, and I cannot
> change it.
>
> Now I want to access the object in JavaScript by the name
> of the checkbox. I cannot use the construct 'elements[2]'
> because the position varies.
>
> I tried theese:
> document.forms[0].action[new].click();
> document.forms[0].action\[new\].click();
> document.forms[0].action['new'].click();
> document.forms[0].'action[new]'.click();
> document.forms[0].'action\[new\]'.click();
>
> Must I check the name of each element to get the object?
> "for each $this as element if $this.name = 'action[new]' $this.click;"
>
> Isn't there another way?
>
> TIA,
> Patrick Bierans
>
> P. Bierans
>
> --
> Patrick Bierans - LYNET Kommunikation AG - http://www.lynet.de
> Das Internet-Systemhaus fuer Multimedia- und Netzwerkloesungen
> Zentrale Luebeck      Fon +49-451-6131-0, Fax +49-451-6131-333
> Niederlassung Hamburg Fon +49-40-65738-0, Fax +49-40-65738-333
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> http://www.LaTech.edu/mailman/listinfo/javascript

--
Shop at ssistant Add-ons and Developer Workshops
http://www.aflyingstart.net/addons/

Enquiries regarding Shop at ssistant Classic training :
Call 01256 880770

Rodney Myers
Based in Oxford, England
Technical Director, Shop at ssistant eCommerce Solutions






More information about the Javascript mailing list