/    Sign up×
Community /Pin to ProfileBookmark

need help with setting select

I’m trying to set the selected value of a pulldown on a form. I think there is a problem with this syntax

[CODE]for(s = 0; s < document.getElementById(‘dozen[‘ + i + ‘]’).length; index++) {
if(document.getElementById(‘dozen[‘ + i + ‘]’)[s].value == selectedDozen){
document.getElementById(‘dozen[‘ + i + ‘]’).selectedIndex = s;
}
}
[/CODE]

Any help?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERJun 26.2010 — You code is somewhat confusing to me ... ?

What does a sample element of 'dozen[?]' look like?

Are you trying to set multiple values of the elements "selectedIndex"?

What is the value of the variable 'i' and where is it initialized/changed?

And where does the 'index' variable come from and why increment it instead of i++ in the loop?
Copy linkTweet thisAlerts:
@KorJun 28.2010 — <i>
</i>document.getElementById('dozen[' + i + ']').length

There may not exist something like that. The id must be unique on document, thus you can not have more than a single element with a certain id.
×

Success!

Help @Eduguy 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.16,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

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