Google Answers Logo
View Question
Q: for djbaker-ga ( Answered 5 out of 5 stars,   0 Comments )
Subject: for djbaker-ga
Category: Computers > Programming
Asked by: marcfest-ga
List Price: $20.00
Posted: 12 May 2006 13:05 PDT
Expires: 11 Jun 2006 13:05 PDT
Question ID: 728196
Hi DJBaker - Pls take a look at the source code at and tweak it so that the JS
will also remember values in "Your email address", "Your name" and
"Subject" and "Message". Thank you.
Subject: Re: for djbaker-ga
Answered By: djbaker-ga on 12 May 2006 15:20 PDT
Rated:5 out of 5 stars
Thank you very much for asking me to work on this follow up.  I am
glad that you are happy with your previous answer.  Below you will
find the modified code.  My suggestion if you decide to store any
additional information would be to move to a database system for user
info storage.  This could be accomplished rather simply if you know
MySQL.  You would simply place and ID cookie with some form of unique
identifying number.  Then when the person comes back to the page it
would grab the id and check the database for that persons info.

With the amount of info you are currently storing though, using
cookies is not a problem.

Here is the new code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="" id="sixapart-standard">

<script type="text/javascript">
//Declare the global variables
var form;
var us_email;
var check;
var us_name;
var subj;
var rec_email;
var mesg;

//This function sends the form as well as sets the cookie.  
function send() {
  var us_email_value = us_email.value;
  var us_name_value = us_name.value;
  var subj_value = subj.value;
  var rec_email_value = rec_email.value;
  var mesg_value = mesg.value;
  var date = new Date();
  var date2 = new Date();
    if (check.checked) {
        var expires = "; expires="+date.toGMTString();
        if (us_email_value != null)
        createCookie("user_email", us_email_value, expires);
        if (us_name_value)
        createCookie("user_name", us_name_value, expires);
        if (subj_value)
        createCookie("subject", subj_value, expires);
        if (rec_email_value)
        createCookie("recpt_email", rec_email_value, expires);
        if (mesg_value)
        createCookie("message", mesg_value, expires);
    else {
    var expires = "; expires="+date2.toGMTString();
        createCookie("user_email", " ", expires);
        createCookie("user_name", " ", expires);
        createCookie("subject", " ", expires);
        createCookie("recpt_email", " ", expires);
        createCookie("message", " ", expires);
    //alert ("here");

function createCookie(name, value, expires) {
 document.cookie = name+"="+value+expires+"; path=/";

//This function loads on page load and checks for an existing cookie

function init() {
form = document.getElementById("form1");
us_email = document.getElementById("user_email");
check = document.getElementById("checky");
us_name = document.getElementById("user_name");
subj = document.getElementById("subject");
rec_email = document.getElementById("recip_email");
mesg = document.getElementById("message");

    if (document.cookie) {
     var cookie_user_email =  getCookieValue("user_email");
     var cookie_user_name =  getCookieValue("user_name");      
     var cookie_subject =  getCookieValue("subject");  
     var cookie_recpt_email=  getCookieValue("recpt_email");
     var cookie_message =  getCookieValue("message");
            if (cookie_user_email) {
            us_email.value = cookie_user_email; }
            if (cookie_user_name) {
            us_name.value = cookie_user_name; }
            if (cookie_subject) {
            subj.value = cookie_subject; }
            if (cookie_recpt_email) {
            rec_email.value = cookie_recpt_email; }
            if (cookie_message) {
            mesg.value = cookie_message; }


function getCookieValue(cookieName) {

var cookie_array = document.cookie.split(';');

    for(var i=0;i < cookie_array.length;i++) {
        var c = cookie_array[i];
            while (c.charAt(0)==' ') {
             c = c.substring(1,c.length);
            if (c.indexOf(cookieName) == 0) {
            check.checked = true;
            return c.substring(cookieName.length+1,c.length);


	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="generator" content="" />
	<link rel="stylesheet"
type="text/css" />
	<link rel="alternate" type="application/atom+xml" title="Atom"
href="" />
	<link rel="alternate" type="application/rss+xml" title="RSS 1.0"
href="" />
	<link rel="alternate" type="application/rss+xml" title="RSS 2.0"
href="" />

	<link rel="EditURI" type="application/rsd+xml" title="RSD"
href="" />
			<link rel="meta" type="application/rdf+xml" title="FOAF"
href="" />

<body class="layout-two-column-left" onload="init()">
	<div id="container">
		<div id="container-inner" class="pkg">
			<!-- banner -->
<div id="banner">
	<div id="banner-inner" class="pkg">
		<h1 id="banner-header"><a
		<h2 id="banner-description">A video blog to boost your day. Shot on
South Beach. Just after sunrise.</h2>

			<div id="pagebody">
				<div id="pagebody-inner" class="pkg">
					<div id="alpha">
						<div id="alpha-inner" class="pkg">

	<div class="module-archives module">

width="200" height="258" alt="Marc on the beach">
<br>Marc on the Beach <br><br>.
<!-- user photo -->

<div class="module-syndicate module">

					<div id="beta">
						<div id="beta-inner" class="pkg">
							<!-- entries -->
	<div class="entry" id="entry-9521233">
					<h3 class="entry-header">Pass it on</h3>
		<div class="entry-content">
			<div class="entry-body">
				<table  align="left" width = "400"><tbody><tr><td>
<form method="POST" action="#" name = "formy" id = "form1">
  <p>Your email address:<br>
  <input type="text" name="sender" id="user_email" size="37" maxlength="200"><br>
  Your name:<br>
  <input type="text" name="sendername" id="user_name" size="37"
  <input type="subject" name="subject" id="subject" value = "Sunrise"
size="37" maxlength="200"><br>
  Email address(es) of recipient(s)<br>
  <input type="text" name="recipients" id="recip_email" size="37"
maxlength="2000" id ="input1"><br>
  (separate multiple addresses by commas)<br>
  <input type="checkbox" name="remember" value="ON" id="checky" >remember<br><br>
  <textarea rows="5" id="message" name="message" cols="44">Check out a
video of today's sunrise at</textarea><br>(You may change the message
  <input type="button" value="Submit" name="B1" 
onClick="send()"><input type="reset" value="Reset" name="B2"></p>

<table CELLSPACING="0" CELLPADDING="0" align = "center">
    <td ALIGN="center"><img
HEIGHT="64" WIDTH="98" ALIGN="TOP"><img
HEIGHT="64" WIDTH="99" ALIGN="TOP"><img
    HEIGHT="64" WIDTH="98" ALIGN="TOP"><img
HEIGHT="64" WIDTH="99"
<a href = "">Main</a> | <a href =


		<p class="entry-footer">

<script type="text/javascript">
src=";page=' +
escape(location.href) + '&amp;referrer=' + escape(document.referrer) +
'" width="1" height="1" alt="" style="position: absolute; top: 0;
left: 0;" />');
// -->


I have tested the above in all 4 of the major browsers (Safari,  Mac
Firefox, Pc Firefox and IE) but should you find any problems, simply
request a clarification and I will see to it as soon as possible.

Thank you for using Google Answers!

marcfest-ga rated this answer:5 out of 5 stars and gave an additional tip of: $5.00
This is working great. Thanks for the speedy turn-around.

There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  

Google Home - Answers FAQ - Terms of Service - Privacy Policy