Google Answers Logo
View Question
 
Q: for djbaker-ga ( Answered 5 out of 5 stars,   0 Comments )
Question  
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
http://www.aftersunrise.com/forward2.cgi and tweak it so that the JS
will also remember values in "Your email address", "Your name" and
"Subject" and "Message". Thank you.
Best,
Marc
Answer  
Subject: Re: for djbaker-ga
Answered By: djbaker-ga on 12 May 2006 15:20 PDT
Rated:5 out of 5 stars
 
Greetings!
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"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" id="sixapart-standard">
<head>

<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();
    date.setTime(date.getTime()+(20000*24*60*60*1000));
    
    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);
    
    }
    form.submit();
    //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; }
   
   
    //alert(document.cookie);
}


}

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;
            //alert(c.substring(cookieName.length+1,c.length));
            return c.substring(cookieName.length+1,c.length);
            
            }
          
    }




}
</script>



	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="generator" content="http://www.typepad.com/" />
	
	
	
	<link rel="stylesheet"
href="http://aftersunrise.typepad.com/after_sunrise/styles.css"
type="text/css" />
	<link rel="alternate" type="application/atom+xml" title="Atom"
href="http://aftersunrise.typepad.com/after_sunrise/atom.xml" />
	<link rel="alternate" type="application/rss+xml" title="RSS 1.0"
href="http://aftersunrise.typepad.com/after_sunrise/index.rdf" />
	<link rel="alternate" type="application/rss+xml" title="RSS 2.0"
href="http://aftersunrise.typepad.com/after_sunrise/rss.xml" />


	<title>AfterSunrise.com</title>
	<link rel="EditURI" type="application/rsd+xml" title="RSD"
href="http://www.typepad.com/t/rsd/316768" />
			<link rel="meta" type="application/rdf+xml" title="FOAF"
href="http://aftersunrise.typepad.com/foaf.rdf" />
	
</head>

<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
href="http://aftersunrise.typepad.com/after_sunrise/"
accesskey="1">AfterSunrise.com</a></h1>
		<h2 id="banner-description">A video blog to boost your day. Shot on
South Beach. Just after sunrise.</h2>
	</div>
</div>

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

	<div class="module-archives module">
	
	</div>

<img
src="http://www.aftersunrise.com/marc_beach.jpg"
width="200" height="258" alt="Marc on the beach">
<br>Marc on the Beach <br><br>.
<!-- user photo -->

<div class="module-syndicate module">
</div>




						</div>
					</div>
					<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>
  <br>
  Your name:<br>
  <input type="text" name="sendername" id="user_name" size="37"
maxlength="200"><br><br>
   Subject:<br>
  <input type="subject" name="subject" id="subject" value = "Sunrise"
size="37" maxlength="200"><br>
<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>
  <br>
  <input type="checkbox" name="remember" value="ON" id="checky" >remember<br><br>
  Message:<br>
  <textarea rows="5" id="message" name="message" cols="44">Check out a
video of today's sunrise at
http://www.aftersunrise.com.</textarea><br>(You may change the message
above)<br>
  <br>
  <input type="button" value="Submit" name="B1" 
onClick="send()"><input type="reset" value="Reset" name="B2"></p>
  </form>
  
  <br><br>

<table CELLSPACING="0" CELLPADDING="0" align = "center">
  <tr>
    
    <td ALIGN="center"><img
SRC="http://www.marcfest.com/festnet/htdocs/marc/beach3-120.jpg"
HEIGHT="64" WIDTH="98" ALIGN="TOP"><img
    SRC="http://www.marcfest.com/festnet/htdocs/marc/beach4-120.jpg"
HEIGHT="64" WIDTH="99" ALIGN="TOP"><img
SRC="http://www.marcfest.com/festnet/htdocs/marc/beach5-120.jpg"
    HEIGHT="64" WIDTH="98" ALIGN="TOP"><img
SRC="http://www.marcfest.com/festnet/htdocs/marc/beach1-120.jpg"
HEIGHT="64" WIDTH="99"
    ALIGN="TOP"></td>
  </tr>
</table>
<br>
<a href = "http://www.aftersunrise.com">Main</a> | <a href =
"http://www.marcfest.com/email.html">Contact</a>
				</td></tr>

</tbody></table>


			</div>
			
		</div>
		<p class="entry-footer">
	</div>


						</div>
					</div>
				</div>
			</div>
			
		</div>
	</div>
	
<script type="text/javascript">
<!--
document.write('<img
src="http://www.typepad.com/t/stats?blog_id=316768&amp;page=' +
escape(location.href) + '&amp;referrer=' + escape(document.referrer) +
'" width="1" height="1" alt="" style="position: absolute; top: 0;
left: 0;" />');
// -->
</script>

</body>
</html>




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!

Best,
djbaker-ga
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.

Comments  
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 answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


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