1

I have a html select list menu,when user select an option he/she is redirected to the page of choice. for example he/she will be redirected to http://example.com/towns/Faizabad below is the selection menu,this acts as a jump menu.

  <select name="cities">
  <option value="towns/Antaliya" id="city1">Antaliya</option>
  <option value="towns/Faizabad" id="city2">Faizabad</option>
  </select>

I need when user(logged/anonymous) selects a city... to add attributed selected, and remember the option for several days until user changes again to another option. I am not good with Javascript/jquery.. i think it can be achived with cookies. Any help will be appreciated.

mrcniceguy
  • 113
  • 3
  • 1
    That would require a decent amount of coding for someone to take their time to solve this issue. I would start off by reading on grabbing cookies and setting a value equal to the option value. Then use jquery to get the value of the cookie and use jquery to make the selection active on page load. Begin this and repost your question with more code and people will help. – chadpeppers Apr 01 '12 at 00:57

2 Answers2

1

Correct, you can use a cookie.

setcookie("myTown", $_POST['cities'], time()+3600*48);  // expires in 48 hours

In your form you can use

if(isset($_COOKIE["myTown"])) {
   echo "<option value=\"" . $_COOKIE["myTown"] . "\">Your Town</option>";
}

Or you can redirect them to the town directly, by using

if(isset($_COOKIE["myTown"])) {
   header("Location: http://yoursite.com/towns/" . $_COOKIE["myTown"])
}

You can find more information about cookies here: http://php.net/manual/en/function.setcookie.php

ArendE
  • 957
  • 1
  • 8
  • 14
0

You can use this plug-in http://www.ashishblog.com/blog/jquery-cookie-example/ then set your cookies after cities selection

$('select[name=\'cities\']').change(function(){
$.cookie('city', $(this).val());
});
Frenchi In LA
  • 3,139
  • 3
  • 25
  • 41