I am working on a form that will save cookie information for visitors. I want it to work like this:
When a user submits the registration form, it should store cookies containing the user’s information such as name, company, and so on. If a user attempts to register a second time with the same name, display a confirm dialog box asking if he or she wants to register again.
I can’t get this to work at all. This is my first time working with cookies to actually save data so any help would be appreciated. What am I doing wrong?
Here’s my code so far:
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“
<html xmlns=”
<head>
<title>Marketing Seminar</title>
<script type=”text/javascript”>
function registerForm()
{
document.cookie = “firname=” + encodeURIComponent(document.form1.fname.value);
document.cookie = “lasname = last_name” + encodeURIComponent(document.form1.lname.value);
var reregister = true
if (document.cookie = null)
{
var firstName = “”
var lastName = “”
firstName = decodeURIComponent(document.cookie)
window.alert(‘Would you like to re-register?’)
else
reregister = false
window.alert(‘Thank you for registering!’)
}
</script>
</head>
<body>
<h1>Marketing Seminar Registration</h1>
</br>
<form action=”” name=”form1″>
First Name: <input type=”text” size=”15″ name=”fname”>
Last Name: <input type=”text” size=”15″ name=”lname”>
</br>
Street Address1: <input type=”text” size=”50″ name=”saddress1″>
</br>
Street Address 2: <input type=”text” size=”50″ name=”saddress2″>
</br>
City: <input type=”text” size=”30″ name=”city”>
State: <input type=”text” size=”2″ name=”state”>
Zip: <input type=”text” size=”5″ name=”zip”>
</br>
Phone: <input type=”text” size=”15″ name=”phone”>
Fax: <input type=”text” size=”15″ name=”fax”>
</br>
Name you would like on your badge: <input type=”text” size=”30″ name=”bname”>
</br></br>
<input type=”button” name=”submit” value=”Submit” onclick=”registerForm();”>
</form>
<script type=”text/javascript”>
</script>
</body>
</html>