note 26121 deleted from language.types.array by mazzanet
| From: | mazzanet@php.net | Date: | Wed, 23 Nov 2005 09:24:03 +0000 |
| Subject: | note 26121 deleted from language.types.array by mazzanet | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-98968@lists.php.net to get a copy of this message | ||
Note Submitter:
----
Why array-style names won't work with Javascript is actually quite logical. If you take:
<input type="text" name="Settings[Name]">
as an example, then this JavaScript code:
document.forms.FormNameHere.elements.Settings[Name].value
won't work, of course! Name is an undefined constant in this case, as it's interpreted as
a constant, not as a string... But adding quotes won't help you:
document.forms.FormNameHere.elements.Settings["Name"].value
Since the name="Settings[Name]" in the tag won't result in a
"Settings"-subarray of the form.FormNameHere.elements array in the DOM.
The solution? Use this:
document.forms.FormNameHere.elements["Settings[Name]"].value
"Settings[Name]" is looked up in the elements array, and is found... The elements array is
a hash, so strings can be used as keys!