Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-11-2004, 09:41 AM   PM User | #1
MikeyMike
New to the CF scene

 
Join Date: Nov 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
MikeyMike is an unknown quantity at this point
Autofill form text field with a cookie variable

Hi Guys,

Here's hoping you can help....

I have the following code - not elegant but it works to a point (you may notice I'm a new comer after reading!) I have the cookie written but need to autofill the text fields with the data present in the cookie. How do you call the variable? Does it go in the HTML input tag value parameter? When I do this it just gives me the literal text:

"<script>document.write(Title)</script>"

How do I get it so it shows "Mr" (if that was the input)?

The code:

<html>

<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<title>Form Output</title>

<script language="JavaScript">
var cookie_stuff = unescape(document.cookie);
var crumbs = cookie_stuff.split("|");
var Title = crumbs[0];
var First = crumbs[1];
var Last = crumbs[2];
var Position = crumbs[3];
var Company = crumbs[4];
var Telephone = crumbs[5];
var Email = crumbs[6];
function process(){
var Title = document.Form1.Title.value;
var First = document.Form1.First.value;
var Last = document.Form1.Last.value;
var Position = document.Form1.Position.value;
var Company = document.Form1.Company.value;
var Telephone = document.Form1.Telephone.value;
var Email = document.Form1.Email.value;
var stuff_for_cookie = Title + "|" + First + "|" + Last + "|" + Position + "|" + Company + "|" + Telephone + "|" + Email;

var now = new Date();
now.setTime(now.getTime() + 1000 * 60 * 60 * 24)

document.cookie = escape(stuff_for_cookie)+ ";expires=" + now;
}
</script>

</head>
<body bgcolor="#ffffff">
<form action="(Empty Reference!)" method="get" name="Form1">
<input type="text" name="Title" size="50" value="<script>document.write(Title)</script>">Title
<p><input type="text" name="First" size="50">First</p>
<p><input type="text" name="Last" size="50">Last</p>
<p><input type="text" name="Position" size="50">Position</p>
<p><input type="text" name="Company" size="50">Company</p>
<p><input type="text" name="Telephone" size="50">Telephone</p>
<p><input type="text" name="Email" size="50">Email</p>
<p><input type="submit" name="Submit" value="Submit" onClick="process()"></p>
</form>
<p></p>
</body>

</html>

I also need to get rid of the undefined text if there is no cookie.

Can you please help?

Kind regards,
Mike
MikeyMike is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:27 AM.


Advertisement
Log in to turn off these ads.