/    Sign up×
Community /Pin to ProfileBookmark

Reading dynamically named form element’s value

I need to read data from a dynamically named form element. Sometimes the element will start with the word “New” and sometimes it will be “Upd.”

I’m using the following function to test which one exists:

function isObject(element) {
return (typeof element == ‘object’);
}

Why will the following not work? I get an ‘Expected Identifier’ error.

if (isObject( document.frmData.[“New-” + arr1[h] + “-” + arr2[h] ] ) == true) {
alert( document.frmData.[“New-” + arr1[h] + “-” + arr2[h] ].value )
}

The arrays hold the rest of the dynamic name. I’ve checked the value of

[“New-” + arr1[h] + “-” + arr2[h] ]

with an alert box–it is the correct element name. Why won’t this work?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@fredmvJan 13.2004 — Consider the following piece of code:[size=3]document.frmData[b][color=red].[/color][/b]["New-" + arr1[h] + "-" + arr2[h] ][/size]Try removing that dot.
Copy linkTweet thisAlerts:
@BananaQuaaludeauthorJan 13.2004 — And that will do it!

Thanks for being the extra set of eyes- what a difference that makes sometimes!
×

Success!

Help @BananaQuaalude 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.18,
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,
)...