/    Sign up×
Community /Pin to ProfileBookmark

How do I dynamically set an option in a dropdown box to "selected"?

Hi

How do I dynamically set an option in a dropdown box to “selected”?

eg.

[code]
<script language=”javascript”>
function autoSelect(opt)
{
document.i.say.option[opt].selected; // ????? what should this line look like??? or how do I go about it?
}
</script>

<body onLoad=”autoSelect(2);”>
<form name”i”>
<select name”say”>
<option value=”a1″ selected>hello</option>
<option value=”a2″>bye</option>
</select>
</form>
</body>
[/code]

Any help or pointers please

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@Khalid_AliJul 31.2005 — somethig like this will work

document.i.say[opt].selected = true;
Copy linkTweet thisAlerts:
@slyfoxauthorJul 31.2005 — Thanks Khalid

You're the only person on the internet today that could give me a correct straight answer. Other stuff I've seen probably has more than 20 lines of code... don't ask me how...

Take Care
Copy linkTweet thisAlerts:
@Khalid_AliAug 01.2005 — my pleasure....
×

Success!

Help @slyfox 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.19,
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,
)...