/    Sign up×
Community /Pin to ProfileBookmark

Select box question…

Hi, i`m using select box a value of which I`m putting in the database. The problem is that when I select some of the values and hit submit, it still shows the default value (but in the database it inputs the users choise). How to make it show the previously selected value?
For insance:

<select name=”contact_type”>

<option value=”nothing”> </option>

<option value=”Skype”>Skype</option>

<option value=”MSN”>MSN</option>

<option value=”Twitter”>Twitter</option>

<option value=”Facebook”>Facebook</option>

<option value=”Yahoo”>Yahoo!</option>
</select>

if the user selects MSN after the submission I want it to stay after the refresh, not to go back to the default furst value, do you understand what I mean?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@MindzaiJun 26.2009 — Assuming your form is submitting via post:

[code=php]
<?php
function selected($item) {
return (isset($_POST['contact_type']) && $_POST['contact_type'] == $item) ? ' selected="selected"' : null;
}
?>

<select name="contact_type">

<option value="nothing"<?php echo selected('nothing') ?>> </option>

<option value="skype"<?php echo selected('skype') ?>> </option>

... etc
[/code]
×

Success!

Help @psicloone 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.28,
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,
)...