calendarxp Site Admin
Joined: 30 Jan 2005 Posts: 409
|
Posted: Tue Nov 14, 2006 3:33 pm Post subject: How to access a form field whose name has brackets or dots in it? |
|
|
Although this has nothing to with calendarxp, we'd love share a tip with our users.
Some web framework requires the field name to contain brackets, e.g. param['abc'], or dots, e.g. obj.txt. In order to access those fields in javascript, you cannot use the normal way like form1.field1 directly, because it will look like form1.obj.txt and will confuse the javascript engine as it interprets as getting the txt attribute of field obj in form1, instead of field "obj.txt" in form1.
The solution is to use the associative array feature of javascript instead, i.e. form1.elements["obj.txt"] or form1.elements["param['abc']"]. This way, the javascript engine will correctly parsing the name and give you the right element(field) of form instead of an object-not-found error.
_________________ Copyright 2003-2011 Idemfactor Solutions, Inc. All rights reserved. |
|