note 26121 added to language.types.array
| From: | php-general at lists dot php dot net | Date: | Fri, 18 Oct 2002 15:57:56 +0000 |
| Subject: | note 26121 added to language.types.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-38257@lists.php.net to get a copy of this message | ||
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!
--
http://www.php.net/manual/en/language.types.array.php
http://master.php.net/manage/user-notes.php?action=edit+26121
http://master.php.net/manage/user-notes.php?action=delete+26121
http://master.php.net/manage/user-notes.php?action=reject+26121