/    Sign up×
Community /Pin to ProfileBookmark

Select item in combo box

I have a page that calls up an item for a user to edit. Included is a combo box that lists different categories.

How do I set the selected property of that combo box to whatever is already in that field for the record?

For example, let’s say the user selected “computer” from among the choices in the combo box when he originally added the item. When someone goes back to edit the item, how do I make the combo box automatically select “computer”?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@JonaSep 06.2003 — [font=arial][color=maroon]Your best bet is to go server-side with this and use a database to include the "selected" attribute of a specific option (in this case, "computer") since the user would need to be logged in. But in any case, this is the code that you would use to select the [i]second[/i] option in a select box.[/color][/font]

[font=monospace]

<script type="text/javascript"><!--

function select2(f){

f.sel.options[1].selected=true;

}

//--></script></head>

<body onload="select2(document.forms[0]);">

<form action=""><div>

<select name="sel">

<option value="-1">--SELECT--</option>

<option value="computer">Computer</option>

</select>

</div></form>

</body></html>

[/font]

[b][J]ona[/b]
×

Success!

Help @kyberspace 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.17,
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,
)...