Accessing form Element with spaces as part of the Element name
| Date: | 11 October 2004 |
|---|---|
| Product/Release: | LANSA for the Web |
| Abstract: | Accessing form Element with spaces as part of the name |
| Submitted By: | LANSA Technical Support |
| Last Review: | November 2010 |
Description:
To allow value retrieval from a field and be able to place values in it without needing to rename the field as 9 characters or remove the spaces after the field name. This method can also be used in fields in browselists.
Solution:
Instead of using:
document.form name>.<element name>.value
there is a simpler method:
document.forms['<form name>']['<element name>'].value
Example:
These examples use field names with spaces around the field name, i.e. "LANSA FIELD NAME ". They retrieve and place values using the new techniques.
Result:
Note: There are obviously other ways to access field name with spaces. The method the LANSA default script currently uses loops through ALL the elements inside a HTML page and stops when it finds a correct match. The newer method suggested here, is more efficient and allows "soft-coding" with JavaScript, i.e. a developer can use a variable as the field name, and it does not need to be done with static call to field name.