/    Sign up×
Community /Pin to ProfileBookmark

Javascript – Remember what was selected after refresh

Hi all,

I have a simple drop down that allows you to choose a country. On my site if the address in the form comes out wrong it refreshes the page and brings up a validation box. If someone choses Canada it defaults back to the US when the page refreshes. With javascript could it remember Canada after the refresh?

[code=html]
<td>
<select name=”scoShipCountry”>
<option value=”US”>United States</option>
<option value=”CA”>Canada</option>
</select>
</td>
[/code]

Thanks

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@WolfShadeMay 27.2011 — You could append the URL with parameters (document.html?country=CAN) and keep appending the URL with them if they exist.

Easier, though, would be cookies. Set a value in document.cookie for country, and have JavaScript check for the existence of the cookie on every page load - if it exists, grab the value and set the select for that value.

Even easier, though, would be a server-side solution (ColdFusion, ASP, PHP, JSP, etc.) You'd be able to set the SELECTED parameter of that option as the form is being built.
Copy linkTweet thisAlerts:
@jbatzel1May 27.2011 — Thanks!
Copy linkTweet thisAlerts:
@WolfShadeMay 27.2011 — np.. lmk which option you decided to go with. I'm curious.
×

Success!

Help @jjbatzel1 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.15,
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,
)...