/    Sign up×
Community /Pin to ProfileBookmark

Set Cookie then Redirect

I have a webpage that includes a map of the U.S. and for each state I have a menu to different city websites for each state. What I would like to do is once a visitor clicks on one of the city links, a cookie is created so that when that user returns to my website, he is taken directly to the city he selected, not the home page again.

I have a script that I am working on but I am getting errors with it. I was hoping someone here could help me. I am not a developer and know very little about scripting, so any ideas or advice are helpful.

Here is the script in the HEAD section of my page:

[CODE]<SCRIPT type=’text/javascript’>
function setCookie(c_name, value, expiredays)
{
var exdate = new Date();
exdate.setDate(exdate.getDate() + expiredays);
document.cookie=c_name + “=” + escape(value)+
((expiredays==null) ? “” : “;expires=”+exdate.toGMTString())
}

function GetDocsInCity()
{
var mylist = document.getElementById(“myList”);

var myCity = mylist.values[mylist.selectedIndex].text;
setCookie(‘myCity’,myCity,365)

var url = “http://fleabay.net/”;
document.location.href = url + myCity;
}

</SCRIPT>[/CODE]

A sample of the HTML code looks like this:

[code=html]<UL id=mylist>
<li value=”ocala”><a onclick=GetDocsInCity()>Ocala</a></li>
<li value=”orlando”><a onclick=GetDocsInCity()>Orlando</a><li>
<li value=”miami”><a onclick=GetDocsInCity()>Miami</a></li>
<li value=”thevillages”><a onclick=GetDocsInCity()>The Villages</a></li>
</UL>[/code]

The page this is at is fleabay.net/index2.php

I actually have not set up all the cities yet, but I figured if I get this part figured out, I can set the rest of the cities just fine.

Thank You for your help.

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @big24fan 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.18,
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,
)...