Click to See Complete Forum and Search --> : Cookies in a feedback form
dtennant9
11-12-2003, 05:56 AM
Hi
I am currently trying to have a feedback form on a website where the user enters their name and email address. I need to make it so that the next time they return their name and email address will be in the name and email fields of the form.
I know I obviously need to do this with cookies and in some way linked to my submit button but I am unsure on exactly how to do this.
Khalid Ali
11-12-2003, 06:32 AM
may be this will give you an idea
http://www.webapplikations.com/pages/html_js/document/CompleteCookieUseage.html
Charles
11-12-2003, 06:42 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>
<style type="text/css">
<!--
label {display:block; margin:1em 0em}
input {display:block}
-->
</style>
<script type="text/javascript">
<!--
String.prototype.isEmailAddress = function () {return this.match(/^[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+(?:\.[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+)*\@[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+(?:\.[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+)+$/)}
expire = new Date();
expire.setFullYear(expire.getFullYear() + 1);
function setCookie (name, value) {document.cookie = name + "=" + escape(value) + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))}
function getCookie (name) {if (new RegExp(name + '=([^;]+);', '').test(document.cookie)) return unescape (RegExp.$1)}
// -->
onload = function () {document.forms[0].name.value = getCookie('name') ? getCookie('name') : ''; document.forms[0].emailAddress.value = getCookie('emailAddress') ? getCookie('emailAddress') : ''}
</script>
<form action="" onsubmit="setCookie('name', this.name.value); setCookie('emailAddress', this.emailAddress.value); return false">
<div>
<label>Name<input id="name" type="text"></label>
<label>E Mail Address<input id="emailAddress" onchange="if (!this.value.isEmailAddress()) {alert('That would not appear to be a valid e-mail address.'); this.value=''; this.focus()}" type="text"></label>
<button type="submit">Submit</button>
</div>
</form>