/    Sign up×
Community /Pin to ProfileBookmark

Is it possible ?

Hello,

I need some help!

Is it possible to use a variable in lets say:
window.document.form.MyTextBox.value

For example I tried this way but it doesn’t work:
window.document.form.MyTextBox’+MyVariable+’.value

I need to do this for a validation template that contains some asp.
The asp complete the name of textbox with a code
Kind of like this:
window.document.form.MyTextBox3465234.value
window.document.form.MyTextBox7846894.value
window.document.form.MyTextBox1258457.value
And for my validation I have the values in variables but I don’t know how to use it.

So anyone knows a way?

Thanks

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@FangOct 05.2005 — document.form.elements['MyTextBox'+MyVariable].value
Copy linkTweet thisAlerts:
@KorOct 05.2005 — or:

document.getElementsByName('MyTextBox'+MyVariable)[0].value
Copy linkTweet thisAlerts:
@skullmurdocauthorOct 05.2005 — document.form.elements['MyTextBox'+MyVariable].value[/QUOTE]

That was quick

thanks a lot
Copy linkTweet thisAlerts:
@tabzterOct 06.2005 — or:

eval("document.form.MyTextBox"+MyVariable+".value");
Copy linkTweet thisAlerts:
@KorOct 06.2005 — if possible, avoid using eval() function. eval() will always invoke the parser, so that it is sometimes dangerouse to evaluate un untrusted string. It might lock up the system resoures. Almost all the time it is better to use square brackets notation or DOM reference to evaluate dynamically a variable.
×

Success!

Help @skullmurdoc 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...