Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

multiple javascript cookies...HELP!!!

Status
Not open for further replies.

annelou

Programmer
Nov 17, 2003
3
0
0
GB
I have a feedback form and want to take the user name and email address and store it using a cookie for every other time they visit the page here is the function code, this workks for name field but not email..

<Script language = &quot;javascript&quot;>

userName =&quot;&quot;
if(document.cookie !=&quot;&quot;){
userName = document.cookie.split(&quot;=&quot;)[1]
}

function setCookie(){
userName =document.form.From_name.value
document.cookie =&quot;userName=&quot;+userName
}

</script>


<body background = &quot;ice03.gif&quot; onLoad =&quot;document.form.From_name.value=userName&quot;>

onBlur=&quot;setCookie()&quot;

Help please
 
<Script language = &quot;javascript&quot;>
//to read the cookies
userName = &quot;&quot;
eMail = &quot;&quot;
if(document.cookie !=&quot;&quot;){
allCookies = document.cookie.split(&quot;; &quot;)
for (x=0; x<allCookies.length; x++){
if (allCookies[x].split[0] == &quot;userName&quot;){
userName = allCookies[x].split[1]
}
else if (allCookies[x].split[0] == &quot;eMail&quot;){
eMail = allCookies[x].split[1]
}
}
}
//to set the cookies
expires = new Date
expires.setMonth = (expires.getMonth + 3)

userName = document.myForm.userName.value
eMail = document.myForm.eMail.value
document.cookie = &quot;userName=&quot; + userName + &quot;;expires=&quot; + expires.toGMTString()
document.cookie = &quot;eMail=&quot; + eMail+ &quot;;expires=&quot; + expires.toGMTString()

</script>


Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
Thanks but that doesn't store the name and email when i re-open the page, heres a copy of the code

<html>
<head>
<title>Feedback</title>
<h2 align = &quot;center&quot;>Feedback Form</h2>

<Script language = &quot;javascript&quot;>

userName = &quot;&quot;
eMail = &quot;&quot;
if(document.cookie !=&quot;&quot;){
allCookies = document.cookie.split(&quot;; &quot;)
for (x=0; x<allCookies.length; x++){
if (allCookies[x].split[0] == &quot;userName&quot;){
userName = allCookies[x].split[1]
}
else if (allCookies[x].split[0] == &quot;eMail&quot;){
eMail = allCookies[x].split[1]
}
}
}
//to set the cookies
expires = new Date
expires.setMonth = (expires.getMonth + 3)

userName = document.myForm.userName.value
eMail = document.myForm.eMail.value
document.cookie = &quot;userName=&quot; + userName + &quot;;expires=&quot; + expires.toGMTString()
document.cookie = &quot;eMail=&quot; + eMail+ &quot;;expires=&quot; + expires.toGMTString()

</script>

</head>


<body >
<p><b>This site was created to collect feedback and opinons on other sites. Simply fill in the details in the form below and we will pass your comments to the relevant people. Thank You.</b></p>

<FORM NAME=&quot;myForm&quot;>
<form method=&quot;POST&quot; action=&quot;<input type=&quot;hidden&quot; name=&quot;To_Email&quot; value=&quot;0102704&quot;@tay.ac.uk&quot;><div align=&quot;center&quot;><center><table border=&quot;1&quot;>

<tr>
<td valign=&quot;top&quot; align=&quot;right&quot;>Enter your Full Name:&nbsp; </td>
<td><input type=&quot;text&quot; name=&quot;From_name&quot; size=&quot;53></td>
</tr>
<tr>
<td valign=&quot;top&quot; align=&quot;right&quot;>Enter your Email Address:&nbsp; </td>
<td><input type=&quot;text&quot; name=&quot;From_Email&quot; size=&quot;53&quot;></td>
</tr>
<tr>
<td valign=&quot;top&quot; align=&quot;right&quot;>Enter a Subject:&nbsp; </td>
<td><input type=&quot;text&quot; name=&quot;subject&quot; size=&quot;53&quot;></td>
</tr>
<tr>
<td valign=&quot;top&quot; align=&quot;right&quot;>Enter your Message:&nbsp; </td>
<td><textarea rows=&quot;12&quot; name=&quot;Message&quot; cols=&quot;46&quot;></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>

<tr>
<td><input type=&quot;submit&quot; value=&quot;Send Message&quot; name=&quot;B1&quot;>
</td>
<td><input type=&quot;reset&quot; value=&quot;Reset&quot; name=&quot;B2&quot;></td>
</tr>

<td>


</table>
</center></div>
</form>
</form>

</body>
</html>

Any more clues?
 
<html>
<head>
<title>Feedback</title>
<h2 align = &quot;center&quot;>Feedback Form</h2>

<Script language = &quot;javascript&quot;>
function readCookies(){
userName = &quot;&quot;
eMail = &quot;&quot;
if(document.cookie !=&quot;&quot;){
allCookies = document.cookie.split(&quot;; &quot;)
for (x=0; x<allCookies.length; x++){
if (allCookies[x].split[0] == &quot;userName&quot;){
userName = allCookies[x].split[1]
}
else if (allCookies[x].split[0] == &quot;eMail&quot;){
eMail = allCookies[x].split[1]
}
}
}
document.myForm.From_name.value = userName
document.myForm.From_Email.value = eMail
}
function setCookies(){
expires = new Date
expires.setMonth = (expires.getMonth + 3)

userName = document.myForm.From_name.value
eMail = document.myForm.From_Email.value
document.cookie = &quot;userName=&quot; + userName + &quot;;expires=&quot; + expires.toGMTString()
document.cookie = &quot;eMail=&quot; + eMail+ &quot;;expires=&quot; + expires.toGMTString()
}
</script>

</head>


<body onLoad=&quot;readCookies()&quot;>
<p><b>This site was created to collect feedback and opinons on other sites. Simply fill in the details in the form below and we will pass your comments to the relevant people. Thank You.</b></p>

<FORM NAME=&quot;myForm&quot; method=&quot;POST&quot; action=&quot;<input type=&quot;hidden&quot; name=&quot;To_Email&quot; value=&quot;0102704&quot;@tay.ac.uk&quot;><div align=&quot;center&quot;><center><table border=&quot;1&quot;>

<tr>
<td valign=&quot;top&quot; align=&quot;right&quot;>Enter your Full Name: </td>
<td><input type=&quot;text&quot; name=&quot;From_name&quot; size=&quot;53&quot; onBlur=&quot;setCookies()&quot;></></td>
</tr>
<tr>
<td valign=&quot;top&quot; align=&quot;right&quot;>Enter your Email Address: </td>
<td><input type=&quot;text&quot; name=&quot;From_Email&quot; size=&quot;53&quot; onBlur=&quot;setCookies()&quot;></td>
</tr>
<tr>
<td valign=&quot;top&quot; align=&quot;right&quot;>Enter a Subject: </td>
<td><input type=&quot;text&quot; name=&quot;subject&quot; size=&quot;53&quot;></td>
</tr>
<tr>
<td valign=&quot;top&quot; align=&quot;right&quot;>Enter your Message: </td>
<td><textarea rows=&quot;12&quot; name=&quot;Message&quot; cols=&quot;46&quot;></textarea></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>

<tr>
<td><input type=&quot;submit&quot; value=&quot;Send Message&quot; name=&quot;B1&quot;>
</td>
<td><input type=&quot;reset&quot; value=&quot;Reset&quot; name=&quot;B2&quot;></td>
</tr>

<td>


</table>
</center></div>
</form>
</form>

</body>
</html>

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top