Beeper
06-01-2005, 03:48 PM
Hi,
I am an absolute beginner at this and almost all of the stuff I read about cookies is about reading values back.
I am trying to do this:
if (!getCookie) {
document.write ('show user registration form with onsubmit="setCookie()"');
} else {
document.write ('some html showing user they have registered');
}
So I need to:
getCookie - if cookie exists show HTML with 'You are registered'
- if cookie doesn't exist show HTML with FORM
setCookie - on the submission of the FORM
Cookie should be valid for 365 days or so.
The whole process is just eluding me and I would really appreciate some enlightenment as my efforts so far are simply to frustrating for words.
Here it is just so you can understand what I am doing wrong:
Head:
<script language="JavaScript">
<!--
var my_Days=365; // Expiry in days
var my_Cookie='landasp'; // Cookie name
function setCookie() {
document.cookie=my_Cookie+"="+escape(value)+";expires="+new Date(new Date().getTime()+my_Days*86400000).toGMTString()+";path=/;"
}
//-->
</script>
I know I haven't defined the getCookie function as this eludes me too...
Body:
<script language="javascript">
if (!getCookie("landasp")){
document.write ('<div class="register"><strong>REGISTER NOW</strong><br>');
document.write ('<span class="side">For availability & offers </span></div>');
document.write ('<div class="register">');
document.write ('<form action="cgi-bin/formProcess.pl" name="reserve" id="reserve" onsubmit="setCookie()">');
document.write ('<input name="recipient" type="hidden" value="stewart@landaspirations.com">');
document.write ('<input name="subject" type="hidden" value="Register Now">');
document.write ('<input type="hidden" name="redirect" value="http://www.landaspirations.com/buying_test.htm">');
document.write ('<input type="hidden" name="formtype" value="Register Now">');
document.write ('<span class=\"side\">Name<br>');
document.write ('<input name="name" type="text" id="name" size=16" class="inputf">');
document.write ('<br>Tel<br>');
document.write ('<input name="tel" type="text" id="tel" size="16" class="inputf">');
document.write ('<br>Email<br>');
document.write ('<input name="email" type="text" id="email" size="16" class="inputf">');
document.write ('Address<br>');
document.write ('<textarea name="address" cols="14" rows="2" class="inputf" id="address"></textarea>');
document.write ('<br><br>');
document.write ('<input type="submit" name="Submit" value="Submit" class="button1">');
document.write ('</span>');
document.write ('</form>');
document.write ('<p class="side">*Details are only used for items relating to LAL.</p></div>');
} else {
document.write ('<div class="register">');
document.write ('<p><strong>THANK YOU FOR REGISTERING</strong></p>');
document.write ('<p class="side">*Details are only used for items relating to LAL.</span></p>');
document.write ('</div>');
}
</script>
I am an absolute beginner at this and almost all of the stuff I read about cookies is about reading values back.
I am trying to do this:
if (!getCookie) {
document.write ('show user registration form with onsubmit="setCookie()"');
} else {
document.write ('some html showing user they have registered');
}
So I need to:
getCookie - if cookie exists show HTML with 'You are registered'
- if cookie doesn't exist show HTML with FORM
setCookie - on the submission of the FORM
Cookie should be valid for 365 days or so.
The whole process is just eluding me and I would really appreciate some enlightenment as my efforts so far are simply to frustrating for words.
Here it is just so you can understand what I am doing wrong:
Head:
<script language="JavaScript">
<!--
var my_Days=365; // Expiry in days
var my_Cookie='landasp'; // Cookie name
function setCookie() {
document.cookie=my_Cookie+"="+escape(value)+";expires="+new Date(new Date().getTime()+my_Days*86400000).toGMTString()+";path=/;"
}
//-->
</script>
I know I haven't defined the getCookie function as this eludes me too...
Body:
<script language="javascript">
if (!getCookie("landasp")){
document.write ('<div class="register"><strong>REGISTER NOW</strong><br>');
document.write ('<span class="side">For availability & offers </span></div>');
document.write ('<div class="register">');
document.write ('<form action="cgi-bin/formProcess.pl" name="reserve" id="reserve" onsubmit="setCookie()">');
document.write ('<input name="recipient" type="hidden" value="stewart@landaspirations.com">');
document.write ('<input name="subject" type="hidden" value="Register Now">');
document.write ('<input type="hidden" name="redirect" value="http://www.landaspirations.com/buying_test.htm">');
document.write ('<input type="hidden" name="formtype" value="Register Now">');
document.write ('<span class=\"side\">Name<br>');
document.write ('<input name="name" type="text" id="name" size=16" class="inputf">');
document.write ('<br>Tel<br>');
document.write ('<input name="tel" type="text" id="tel" size="16" class="inputf">');
document.write ('<br>Email<br>');
document.write ('<input name="email" type="text" id="email" size="16" class="inputf">');
document.write ('Address<br>');
document.write ('<textarea name="address" cols="14" rows="2" class="inputf" id="address"></textarea>');
document.write ('<br><br>');
document.write ('<input type="submit" name="Submit" value="Submit" class="button1">');
document.write ('</span>');
document.write ('</form>');
document.write ('<p class="side">*Details are only used for items relating to LAL.</p></div>');
} else {
document.write ('<div class="register">');
document.write ('<p><strong>THANK YOU FOR REGISTERING</strong></p>');
document.write ('<p class="side">*Details are only used for items relating to LAL.</span></p>');
document.write ('</div>');
}
</script>