/    Sign up×
Community /Pin to ProfileBookmark

How do I use a variable in a statement.

[code]
while (i < count){
text=’text’+i;
val=document.forms[0].elements[‘text’+i].value;
myurl += ‘&text’+i+’=’+val
i++;
}[/code]

How do I format the line “val=document.forms[0].elements[‘text’+i].value;” correctly?

I have an unknown amount of text boxes named text1, text2, text3, and so on. And all I need is the values to make a url like additem.php?text1=value1&text2=value2 and so on.

Thanks for the help.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@felgallAug 15.2006 — That would work if it weren't for the text='text'+i; adding the number in one too many times. Get rid of that line and the following one will work fine. I assume you are setting i to 0 or 1 before the loop.
Copy linkTweet thisAlerts:
@ghostz00authorAug 15.2006 — Thanks for the help. That solved it.
×

Success!

Help @ghostz00 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.5,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

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