/    Sign up×
Community /Pin to ProfileBookmark

Javascript enhancement

Could javascript be changed so that single occurances of a form element be refrenced as element[0] rather than forcing us to test for multiple occurances? I don’t think this would break legacy code and only cost a little bit of client side memory.
Here is an example of the kind of code that results from the lack of this feature:
if ( document.act_form.chg.length == null ) {
document.act_form.chg.value = ‘*’
} else {
document.act_form.chg[0].value = ’27’
}

On the otherhand perhaps there is a simple solution that i’m missing. This is particularly useful to those of use who generate input elements as a function of db queries in tools like coldfusion and php.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@NedalsMay 02.2003 — I'm not sure what you are asking...

but form elements can be referenced using:

document.formname.elementname

or

document.formname.elements[n] // note the 's'

or

document.forms[n].elements[n]

A single form with one element would be referenced with..

document.forms[0].elements[0]


Any help??
Copy linkTweet thisAlerts:
@rchoppinauthorMay 02.2003 — That would work with a) a single form having b) a single 1-or-more repeating element, but I have very few of those to deal with. Most of my documents have multiple forms and multiple elements repeating 1 or more times.


You can use the form and element arrays but you have to compare names in order to figure out which element is which.
×

Success!

Help @rchoppin spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.22,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...