Techie dopers, help! Javascript cookies that fill in form fields?

Per my manager’s request, I created a small HTML page that includes a text form field. When you enter a URL in this form field and hit the submit button, you are magically whisked away to the URL you entered. (We needed that page for testing.)

NOW he wants me to include code on that page so that the URL entered into the text field can be saved until it is changed (not just in the current session). Yes, I already told him this is scope creep.

I suspect that this will require Javascript cookies, but my experience with Javascript is very limited (see first paragraph), and I’ve never written a cookie.

I’ve searched the web extensively for this info; many sites say that it can be done but do not go about showing how to do it, at least not with just Javascript. (I would prefer to use Javascript since it’s client-side and this will be running locally, not on a server. Plus I don’t know CGI. Plus it will be running on a Windows system, not a Unix system, so I can’t use Perl–about which I also know very little.)

Please, techie dopers, help! I offer you admiration aplenty if only you will help me. Throw me a bone, a handy tutorial, a patch of code …

Moved per request of skeptic_ev.

Javascript cookie programming is not a simple task. Here are several examples you can use to get started:

http://javascript.internet.com/cookies/

Yeah, tell me about it, ccwaterback. I actually think I got it mostly figured out with the help of a swell tutorial and an old O’Reilly JavaScript book laying around the office. (Man, those O’Reilly books are cool, aren’t they?)

Now I just have to do the onLoad event, which shouldn’t be a big deal.

Hey, I just coded my very first JavaScript anything and my very first cookie. How cool is that? :cool:

BTW, thanks for the link. I think I’m going to play around with cookies at home this weekend.

Hmm … that sounded vaguely dirty, didn’t it?

HA!!! I did my fair share of cookie programming. It’s kinda fun naming your variables though. I starting thinking of myself as the Cookie Monster afterwhile :slight_smile: Good luck with your cookies, I hope they bake to perfection.

Oh, one more thing, friggin Javascript. If you only need to support one version of one browser consider yourself very lucky. Javascript doesn’t port very well.

Case in point. I had trouble with “onLoad”, it worked differently, or not at all, depending on the browser and browser version. So, instead, I would put a Javascript at the end of the HTML to “simulate” onLoad.
<html><head>
<title>Some Page</title>

<script language=“javascript”>
<!-- begin script

TheCookieName = ‘Yummy.In.My.Tummy.Cookie’;

//Set the Cookie with expire date in the past (- 2 days will kill it for sure).
function DelEatCookie () {
var expire = new Date();
expire.setTime (expire.getTime() - 2 * 86400001); //-2 days ago --> stale Cookie
document.cookie = TheCookieName + “=*; expires=” + expire.toGMTString() + “; path=” + “/”;
}

// end script -->
</script>
</head>
<body>

<CENTER><H2>Hello people</H2><HR>
<TABLE>
blah blah blah
</TABLE>

<script language=“javascript”>
<!-- begin script

DelEatCookie(); // Since this function is called on intialization,
// this works like onLoad, but it works better.

// end script -->
</script>

Yup, one version of one browser. This page will be running locally, which is one reason I chose JavaScript; I need something that runs client-side.

Well, I’m going to try to figure out the onLoad thing now. The O’Reilly book isn’t much help in that regard, so I’m off to the web to look for a tutorial. Thanks again, ccwaterback. I don’t care what anyone else says; you’re swell. :wink: