dcsimg
www.webdeveloper.com
Results 1 to 4 of 4

Thread: Javascript - Remember what was selected after refresh

  1. #1
    Join Date
    May 2011
    Posts
    1

    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?

    HTML Code:
    <td>
    	<select name="scoShipCountry">
    	<option value="US">United States</option>
    	<option value="CA">Canada</option>
    	</select>
    </td>
    Thanks

  2. #2
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    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.

  3. #3
    Join Date
    May 2011
    Posts
    3

    Thanks!

    Thanks!

  4. #4
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    np.. lmk which option you decided to go with. I'm curious.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles