Solved

Could someone please add an expiry date to this cookie?

Posted on 2001-07-17
45
311 Views
Last Modified: 2012-06-21

Hello,

I am not very good at javascript and I have been trying to set an expiry date to this form cookie for ages - unsuccessfully!

The script alerts users to the fact they have already submitted the form and gives them the date/time they submitted it.  However, the cookie only seems to remember that the form has been submitted for the duration of the session.  If the user logs off or shuts down the browser and tries to submit again, no alert appears. I would like the script to remember for a much longer period (3 months) no matter how many times the user logs off.

The script goes like this ....

<SCRIPT>
var alreadyclicked = "no";
var cookiename = "datesubmitted";

function mySubmit(){
   if (alreadyclicked == "yes"){
      alert("Form already being processed.");
      return;
   }

   if (document.cookie.indexOf(cookiename) > -1){
      var mystart =document.cookie.indexOf(cookiename);
      var myend = document.cookie.indexOf(";", mystart);
      if (myend < 0){myend = document.cookie.length;}
      var mydate = document.cookie.substring(mystart + cookiename.length + 1, myend+1);

      var myconfirm = "You submitted this form at ";
      myconfirm = myconfirm + mydate;
      myconfirm = myconfirm + ". Submit again?"
      ret = confirm(myconfirm);
      if (ret == false){
         return;
      }
   }

   mydate = new Date();
   document.cookie = cookiename + "=" + mydate;
   alreadyclicked = "yes";
   document.myform.submit();
}

</SCRIPT>

Please remember that I am new to javascript and I need spoonfeeding.

Thanks.
0
Comment
Question by:Gabrielle
  • 19
  • 16
  • 6
  • +3
45 Comments
 
LVL 22

Expert Comment

by:CJ_S
ID: 6289215
expirydate = new Date(today.getTime() + (90 * 86400000)); // a year

function setCookie (name,value,expires,path,theDomain,secure) {
   var theCookie = name + "=" + escape (value) +
   ((expires)    ? "; expires=" + expires.toGMTString() : "") +
   ((path)       ? "; path="    + path   : "") +
   ((theDomain)  ? "; domain="  + theDomain : "") +
   ((secure)     ? "; secure"            : "");
   document.cookie = theCookie;
}


Now call it like:
setCookie("mycookiename", "cookievalue", expiredate);

regards,
CJ
0
 

Author Comment

by:Gabrielle
ID: 6289351

Thanks CJ.

I've just tried to put your expiry date script into the original form script and I get an error that says:

for the line:
setCookie ("mycookiename", "cookievalue", expiredate)
expiredate is undefined

I did it like this .... I know this is wrong.  Could you please make it right?

<SCRIPT>

setCookie("mycookiename", "cookievalue", expiredate);


var alreadyclicked = "no";
var cookiename = "datesubmitted2";


function mySubmit(){


   if (alreadyclicked == "yes"){
      alert("Form already being processed.");
      return;
   }

   if (document.cookie.indexOf(cookiename) > -1){
      var mystart =document.cookie.indexOf(cookiename);
      var myend = document.cookie.indexOf(";", mystart);
      if (myend < 0){myend = document.cookie.length;}
      var mydate = document.cookie.substring(mystart + cookiename.length + 1, myend+1);

      var myconfirm = "SORRY.  You already submitted this form on ";
      myconfirm = myconfirm + mydate;
      myconfirm = myconfirm + ". Submit again?"
       ret = confirm(myconfirm);
       if (ret == false)     {
      return
   }
}
   mydate = new Date();
   document.cookie = cookiename + "=" + mydate;
   alreadyclicked = "yes";
   document.cisEvaluation.submit();
}

expirydate = new Date(today.getTime() + (90 * 86400000));

function setCookie (name,value,expires,path,theDomain,secure)
{
  var theCookie = name + "=" + escape (value) +
  ((expires)    ? "; expires=" + expires.toGMTString() : "") +
  ((path)       ? "; path="    + path   : "") +
  ((theDomain)  ? "; domain="  + theDomain : "") +
  ((secure)     ? "; secure"            : "");
  document.cookie = theCookie;
}

</SCRIPT>
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 6289359
My typo :-(

setCookie("mycookiename", "cookievalue", expirydate);

e should've been an y...my mistake.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:Gabrielle
ID: 6289749

CJ - thanks again for that.

I thought you might have made a typo before and I have already tried the code:

setCookie("datesubmitted", "mydate", expirydate);

... but I still get the same error message.

Have I cut and pasted your code into the right places into the original?



0
 
LVL 22

Expert Comment

by:CJ_S
ID: 6289979
Check your browser-cache
0
 
LVL 9

Expert Comment

by:msdixon
ID: 6290497
you also can use asp to set the cookie as an option... little easier to work with.
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6291075
setCookie('DiskCookie','passed',ExpireDate,'/');

function setCookie (name,value,expires,path,theDomain,secure)
  {
    var theCookie = name + "=" + escape (value) +
    ((expires)    ? "; expires=" + expires.toGMTString() : "") +
    ((path)       ? "; path="    + path   : "") +
    ((theDomain)  ? "; domain="  + theDomain : "");
    document.cookie = theCookie;
  }
0
 

Author Comment

by:Gabrielle
ID: 6293751

Thanks Dave.

I've added your code to the original script but I still get the same message I got when I tried CJ's.

Maybe I've pasted the code into the wrong place?
I haven't changed any of your code either.  Maybe I should have?

I have added a line from CJ's script too.  Maybe I shouldn't have.

As previously, for the line
setCookie('DiskCookie','passed',ExpireDate,'/');

I get the error message
'ExpireDate' is undefined.

The whole script now looks like this ...


<SCRIPT>

var alreadyclicked = "no";
var cookiename = "datesubmitted";


function mySubmit(){


   if (alreadyclicked == "yes"){
      alert("Form already being processed.");
      return;
   }

   if (document.cookie.indexOf(cookiename) > -1){
      var mystart =document.cookie.indexOf(cookiename);
      var myend = document.cookie.indexOf(";", mystart);
      if (myend < 0){myend = document.cookie.length;}
      var mydate = document.cookie.substring(mystart + cookiename.length + 1, myend+1);

      var myconfirm = "SORRY.  You already submitted this form on ";
      myconfirm = myconfirm + mydate;
      myconfirm = myconfirm + ". Submit again?"
       ret = confirm(myconfirm);
       if (ret == false)     {
      return
   }
}
   mydate = new Date();
   document.cookie = cookiename + "=" + mydate;
   alreadyclicked = "yes";
   document.cisEvaluation.submit();
}

setCookie('DiskCookie','passed',ExpireDate,'/');

ExpireDate = new Date(today.getTime() + (90*86400000));

function setCookie (name,value,expires,path,theDomain,secure)
 {
   var theCookie = name + "=" + escape (value) +
   ((expires)    ? "; expires=" + expires.toGMTString() : "") +
   ((path)       ? "; path="    + path   : "") +
   ((theDomain)  ? "; domain="  + theDomain : "");
   document.cookie = theCookie;
 }

</SCRIPT>

Can anyone see where I'm going wrong?  Please!
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 6293758
last part should be:

function setCookie (name,value,expires,path,theDomain,secure)
{
  var theCookie = name + "=" + escape (value) +
  ((expires)    ? "; expires=" + expires.toGMTString() : "") +
  ((path)       ? "; path="    + path   : "") +
  ((theDomain)  ? "; domain="  + theDomain : "");
  document.cookie = theCookie;
}
ExpireDate = new Date(today.getTime() + (90*86400000));
setCookie('DiskCookie','passed',ExpireDate,'/');
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 6293763
The order of the calls is incorrect..
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6293772
Yep I suppose you would, sorry I didn't show setting the date variable

ExpireDate = Date();
0
 

Author Comment

by:Gabrielle
ID: 6293921

Thanks again guys
Now for the line,
ExpireDate = new Date(today.getTime() + (90*86400000));

I get the error message,
'today' is undefined.

Any ideas on what I could try next?

The whole script now looks like this ...


<SCRIPT>

var alreadyclicked = "no";
var cookiename = "datesubmitted";


function mySubmit(){


   if (alreadyclicked == "yes"){
      alert("Form already being processed.");
      return;
   }

   if (document.cookie.indexOf(cookiename) > -1){
      var mystart =document.cookie.indexOf(cookiename);
      var myend = document.cookie.indexOf(";", mystart);
      if (myend < 0){myend = document.cookie.length;}
      var mydate = document.cookie.substring(mystart + cookiename.length + 1, myend+1);

      var myconfirm = "SORRY.  You already submitted this form on ";
      myconfirm = myconfirm + mydate;
      myconfirm = myconfirm + ". Submit again?"
       ret = confirm(myconfirm);
       if (ret == false)     {
      return
   }
}
   mydate = new Date();
   document.cookie = cookiename + "=" + mydate;
   alreadyclicked = "yes";
   document.cisEvaluation.submit();
}

function setCookie (name,value,expires,path,theDomain,secure)
{
 var theCookie = name + "=" + escape (value) +
 ((expires)    ? "; expires=" + expires.toGMTString() : "") +
 ((path)       ? "; path="    + path   : "") +
 ((theDomain)  ? "; domain="  + theDomain : "");
 document.cookie = theCookie;
}
ExpireDate = new Date(today.getTime() + (90*86400000));
setCookie('DiskCookie','passed',ExpireDate,'/');

</SCRIPT>

0
 

Author Comment

by:Gabrielle
ID: 6294018

Thanks again guys
Now for the line,
ExpireDate = new Date(today.getTime() + (90*86400000));

I get the error message,
'today' is undefined.

Any ideas on what I could try next?

The whole script now looks like this ...


<SCRIPT>

var alreadyclicked = "no";
var cookiename = "datesubmitted";


function mySubmit(){


   if (alreadyclicked == "yes"){
      alert("Form already being processed.");
      return;
   }

   if (document.cookie.indexOf(cookiename) > -1){
      var mystart =document.cookie.indexOf(cookiename);
      var myend = document.cookie.indexOf(";", mystart);
      if (myend < 0){myend = document.cookie.length;}
      var mydate = document.cookie.substring(mystart + cookiename.length + 1, myend+1);

      var myconfirm = "SORRY.  You already submitted this form on ";
      myconfirm = myconfirm + mydate;
      myconfirm = myconfirm + ". Submit again?"
       ret = confirm(myconfirm);
       if (ret == false)     {
      return
   }
}
   mydate = new Date();
   document.cookie = cookiename + "=" + mydate;
   alreadyclicked = "yes";
   document.cisEvaluation.submit();
}

function setCookie (name,value,expires,path,theDomain,secure)
{
 var theCookie = name + "=" + escape (value) +
 ((expires)    ? "; expires=" + expires.toGMTString() : "") +
 ((path)       ? "; path="    + path   : "") +
 ((theDomain)  ? "; domain="  + theDomain : "");
 document.cookie = theCookie;
}
ExpireDate = new Date(today.getTime() + (90*86400000));
setCookie('DiskCookie','passed',ExpireDate,'/');

</SCRIPT>

0
 
LVL 22

Expert Comment

by:CJ_S
ID: 6294115
today      = new Date();

sorry :-/
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6294408
Pretty sure you do not need the "NEW" keyword...
0
 

Author Comment

by:Gabrielle
ID: 6294698
Hey guys - I've tried two new endings.

Firstly, with this ending ...

function setCookie (name,value,expires,path,theDomain,secure)
{
 var theCookie = name + "=" + escape (value) +
 ((expires)    ? "; expires=" + expires.toGMTString() : "") +
 ((path)       ? "; path="    + path   : "") +
 ((theDomain)  ? "; domain="  + theDomain : "");
 document.cookie = theCookie;
}
today = new Date();
ExpireDate = new Date(today.getTime() + (90*86400000));
setCookie('DiskCookie','passed',ExpireDate,'/');

 ... I don't get any error messages!

And - when I try to re-submit the form, the alert message appears giving the correct date/time of submission.

But - if I close and re-open my browser and then try to re-submit, the alert message doesn't appear.

And - if I re-start my pc and try to re-submit the alert doesn't appear either.

With the expiry date set to (today + 3 months), if I submit the form and then close and re-open my browser or re-start my pc and try to re-submit, the alert message should appear, shouldn't it?



Secondly, as I wasn't sure what the "new" keyword was, I tried this ending ....

function setCookie (name,value,expires,path,theDomain,secure)
{
 var theCookie = name + "=" + escape (value) +
 ((expires)    ? "; expires=" + expires.toGMTString() : "") +
 ((path)       ? "; path="    + path   : "") +
 ((theDomain)  ? "; domain="  + theDomain : "");
 document.cookie = theCookie;
}
today = Date();
ExpireDate = Date(today.getTime() + (90*86400000));
setCookie('DiskCookie','passed',ExpireDate,'/');

... but, unfortunately, I get the following error message with it.

For the line:
ExpireDate = Date(today.getTime() + (90*86400000));
I get the message:
Object doesn't support this property or method.


What should I try now?
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6294759
As far as the second one, yes you would get the Object error.  this is because when you are dimensioning the variable you are setting it to 'create' a new date like so

today = NEW Date();

When you type

today = Date();

You are just placing the date into the variable today...  which could be a keyword...  need to be careful about that!
0
 

Author Comment

by:Gabrielle
ID: 6294804

Ok Dave - I don't really understand any of that.  Sorry.

Which ending should I continue with?
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6294816
Why don't we just do this

The DateAdd function won't return an invalid date. The following example adds one year to January 31:

NewDate = DateAdd("y", 1, Date())
0
 

Author Comment

by:Gabrielle
ID: 6294992
Dave,

I have now managed to mess up your last suggestion.  I didn't know where to add
NewDate = DateAdd("y", 1, Date())
- so - I hazzarded a guess and changed things a bit.


The ending now goes like this ...

function setCookie (name,value,expires,path,theDomain,secure)
{
 var theCookie = name + "=" + escape (value) +
 ((expires)    ? "; expires=" + expires.toGMTString() : "") +
 ((path)       ? "; path="    + path   : "") +
 ((theDomain)  ? "; domain="  + theDomain : "");
 document.cookie = theCookie;
}

today = new Date();
new Date = DateAdd("y", 1, Date())
ExpireDate = new Date();
setCookie('DiskCookie','passed',ExpireDate,'/');


 ... and the error message I get is the following ...

For the line:
new Date = DateAdd("y", 1, Date())
Error message:
Object Expected


Thank you for being so patient.
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6295005
Ok change these lines

<<
today = new Date();
new Date = DateAdd("y", 1, Date())
ExpireDate = new Date();
>>

to

<<
ExpireDate = DateAdd("y", 1, Date())
>>
0
 

Author Comment

by:Gabrielle
ID: 6297556
Dave,

I've changed that last bit and it now looks like this ....

<<
function setCookie (name,value,expires,path,theDomain,secure)
{
 var theCookie = name + "=" + escape (value) +
 ((expires)    ? "; expires=" + expires.toGMTString() : "") +
 ((path)       ? "; path="    + path   : "") +
 ((theDomain)  ? "; domain="  + theDomain : "");
 document.cookie = theCookie;
}

ExpireDate = DateAdd("y", 1, Date());
setCookie('DiskCookie','passed',ExpireDate,'/');
>>

... and - for the line:
ExpireDate = DateAdd("y", 1, Date());

I get the error message:
Object Expected

Any ideas?
0
 

Author Comment

by:Gabrielle
ID: 6297743
Guys,

I don't know if this is any help - but - a while ago I got this solution ...

<<
function mySubmit() {
cookiename = "alreadysubmitted"
if (document.cookie.indexOf(cookiename) > -1){
 alert("You can only submit this form once.")
 return false;
} else {
 mydate = new Date();
 mydate.setMonth(mydate.getMonth() + 3)
 document.cookie = cookiename + "=" + mydate;
 return true;
}
}

<form onsubmit="return mySubmit();">

>>

.... which I haven't managed to get to work.

This solution also removes the re-submit option that the orginal script offers.
I would like to remove the re-submit option - but - I thought I'd ask another question and offer up some more points for that once I've got the expiry date issue sorted.
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6298215
Have you dimensioned ExpireDate?

Dim ExpireDate
0
 

Author Comment

by:Gabrielle
ID: 6298457
The last bit of the code is like this now ...

<<
function setCookie (name,value,expires,path,theDomain,secure)
{
 var theCookie = name + "=" + escape (value) +
 ((expires)    ? "; expires=" + expires.toGMTString() : "") +
 ((path)       ? "; path="    + path   : "") +
 ((theDomain)  ? "; domain="  + theDomain : "");
 document.cookie = theCookie;
}
 

ExpireDate = DateAdd("y", 1, Date());
setCookie('DiskCookie','passed',ExpireDate,'/');
Dim ExpireDate();

>>


 ... and for the line:
<input type="button" value="Submit" onClick="mySubmit()" name="button">


I get the error message:
Object Expected

We seem to be going round in circles a bit here.  Is this normal?  This is my first question at Devx and I'm new to javascript.
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6298584
I,m Sorry, wrong scripting language... I've been sending you in the wrong direction...  my apologies!!!

<<

var ExpireDate = new Date()
var expDays = 30;  <--- change this value to extend cookie life
ExpireDate.setTime(ExpireDate.getTime() + (expDays*30*24*60*60*1000));

>>
0
 

Author Comment

by:Gabrielle
ID: 6298787

The last bit of the code is like this now ...

<<

function setCookie (name,value,expires,path,theDomain,secure)
{
 var theCookie = name + "=" + escape (value) +
 ((expires)    ? "; expires=" + expires.toGMTString() : "") +
 ((path)       ? "; path="    + path   : "") +
 ((theDomain)  ? "; domain="  + theDomain : "");
 document.cookie = theCookie;
}
 

var ExpireDate = new Date();
var expDays = 90;
ExpireDate.setTime(ExpireDate.getTime() + (expDays*30*24*60*60*1000));



>>



 ... and I don't get any error messages, which makes a nice change!

And - when I try to re-submit the form, I get the correct alert message giving the correct date/time of submission.

But - (and this has happened before) if I close and re-open my browser and try to re-submit the alert message doesn't appear.  The cookie still only seems to last for the duration of the session.

I've looked in my temporary internet files directory to see if anything like our cookie has appeared, and it hasn't.

Thanks again for all your help.
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6299030
Just out of curiousity, you have your browser set to accept cookies, correct?
0
 

Author Comment

by:Gabrielle
ID: 6301943


Yes, I have my browser set to accept cookies.
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6302574
Check your Cache settings...

Tools > Internet Options [General Tab] Settings...

Make sure the settings are set to

"Every visit to the page"

and that you have enough space available for web content...
0
 

Author Comment

by:Gabrielle
ID: 6302781
Dave,

My temporary internet file settings were set to check for newer versions "automatically".  I've now set them to check on "every visit".

But still - when I submit the form and close and re-open my browser and try to re-submit it, no alert message appears and the form is submitted again.

Do you think we are getting any warmer?
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6302828
Just to be certain... this is the code in question.. correct?

<SCRIPT>
var alreadyclicked = "no";
var cookiename = "datesubmitted";

function mySubmit(){
  if (alreadyclicked == "yes"){
     alert("Form already being processed.");  <-- isn't triggered second time around... right?
     return;
0
 

Author Comment

by:Gabrielle
ID: 6307778
Yes - the beginning of the script is as you say.

Here's the whole script again ....

<SCRIPT>

var alreadyclicked = "no";
var cookiename = "datesubmitted";


function mySubmit(){


   if (alreadyclicked == "yes"){
      alert("Form already being processed.");
      return;
   }

   if (document.cookie.indexOf(cookiename) > -1){
      var mystart =document.cookie.indexOf(cookiename);
      var myend = document.cookie.indexOf(";", mystart);
      if (myend < 0){myend = document.cookie.length;}
      var mydate = document.cookie.substring(mystart + cookiename.length + 1, myend+1);

      var myconfirm = "SORRY.  You already submitted this form on ";
      myconfirm = myconfirm + mydate;
      myconfirm = myconfirm + ". Submit again?"
       ret = confirm(myconfirm);
       if (ret == false)     {
      return
   }
}
   mydate = new Date();
   document.cookie = cookiename + "=" + mydate;
   alreadyclicked = "yes";
   document.cisEvaluation.submit();
}

function setCookie (name,value,expires,path,theDomain,secure)
{
 var theCookie = name + "=" + escape (value) +
 ((expires)    ? "; expires=" + expires.toGMTString() : "") +
 ((path)       ? "; path="    + path   : "") +
 ((theDomain)  ? "; domain="  + theDomain : "");
 document.cookie = theCookie;
}
 

var ExpireDate = new Date();
var expDays = 90;
ExpireDate.setTime(ExpireDate.getTime() + (expDays*30*24*60*60*1000));

</SCRIPT>

0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6308691
Ok, if this is the case then I think it's a logic problem.

<SCRIPT>

var alreadyclicked = "no";   <--Variable set when page accessed

Try addding this variable into the cookie, then you can perform a read of the cookie for yes or no.
0
 

Author Comment

by:Gabrielle
ID: 6317044
Dave,

I've tried to put

var alreadyclicked="no"

into the cookie several times in several different places
without success.  I really don't know what I'm trying to do. I keep getting an "error on page" message and I can't submit anything.

Could you show me where to put it?  Please.
Here's what I've done.  Don't laugh too much.

<SCRIPT>

var alreadyclicked = "no";
var cookiename = "datesubmitted";


function mySubmit(){


   if (alreadyclicked == "yes"){
      alert("Form already being processed.");
      return;
   }
   
   if (alreadyclicked == "no"){
      function setCookie (datesubmitted);
   }

   if (document.cookie.indexOf(cookiename) > -1){
      var mystart =document.cookie.indexOf(cookiename);
      var myend = document.cookie.indexOf(";", mystart);
      if (myend < 0){myend = document.cookie.length;}
      var mydate = document.cookie.substring(mystart + cookiename.length + 1, myend+1);

      var myconfirm = "SORRY.  You already submitted this form on ";
      myconfirm = myconfirm + mydate;
      myconfirm = myconfirm + ". Submit again?"
       ret = confirm(myconfirm);
       if (ret == false)     {
      return
   }
}
   mydate = new Date();
   document.cookie = cookiename + "=" + mydate;
   alreadyclicked = "yes";
   document.cisEvaluation.submit();
}

function setCookie (name,value,expires,path,theDomain,secure)
{
 var theCookie = name + "=" + escape (value) +
 ((expires)    ? "; expires=" + expires.toGMTString() : "") +
 ((path)       ? "; path="    + path   : "") +
 ((theDomain)  ? "; domain="  + theDomain : "");
 document.cookie = theCookie;
}
 

var ExpireDate = new Date();
var expDays = 90;
ExpireDate.setTime(ExpireDate.getTime() + (expDays*30*24*60*60*1000));


</SCRIPT>
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6317092
Ok, the first thing you need to do while opening the page is to read from the cookie if it exists.  

If it exists and the value alreadyclicked = yes then you bypass the submit.  

If the cookie's alreadyclicked = no then you can process the submit.  

If the cookie doesn't exist then alreadyclicked = no
0
 
LVL 8

Accepted Solution

by:
Dave_Greene earned 100 total points
ID: 6317110
In other words, you do not set the value in the page, you only set the value in the cookie.  Then to get the value, you read the cookie and put it in a variable.

pseudo code

if submit = true then
   put yes in cookie
end if

if open page then
   look in cookie for alreadyclicked entry
   if entry exists then
      put entry in variable
   else
      alreadyclicked = no
   end
end if
0
 

Author Comment

by:Gabrielle
ID: 6322549
Dave,

I'm still here.  Trying my best to sort this cookie out.

My script now looks like this ....


<SCRIPT>

var alreadyclicked = "no";
var cookiename = "datesubmitted";


function mySubmit(){


   if (alreadyclicked == "yes"){
      alert("Form already being processed.");
      return;
   }
   
   if (alreadyclicked == "no"){
      function setCookie (datesubmitted);
   }

   if (document.cookie.indexOf(cookiename) > -1){
      var mystart =document.cookie.indexOf(cookiename);
      var myend = document.cookie.indexOf(";", mystart);
      if (myend < 0){myend = document.cookie.length;}
      var mydate = document.cookie.substring(mystart + cookiename.length + 1, myend+1);

      var myconfirm = "SORRY.  You already submitted this form on ";
      myconfirm = myconfirm + mydate;
      myconfirm = myconfirm + ". Submit again?"
       ret = confirm(myconfirm);
       if (ret == false)     {
      return
   }

else (alreadyclicked == "no") {


}
   mydate = new Date();
   document.cookie = cookiename + "=" + mydate;
   alreadyclicked = "yes";
   document.cisEvaluation.submit();
}

function setCookie (name,value,expires,path,theDomain,secure)
{
 var theCookie = name + "=" + escape (value) +
 ((expires)    ? "; expires=" + expires.toGMTString() : "") +
 ((path)       ? "; path="    + path   : "") +
 ((theDomain)  ? "; domain="  + theDomain : "");
 document.cookie = theCookie;
}
 

var ExpireDate = new Date();
var expDays = 90;
ExpireDate.setTime(ExpireDate.getTime() + (expDays*30*24*60*60*1000));

}

</SCRIPT>

... but I still get an "Error on page" message.

Do you think it would be worth submitting the question again and offering another
100 points?

- Or - do you think you have nearly cracked it?

0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6322618
You didn't make the changes I proposed!

You need to...

<SCRIPT>

var alreadyclicked = "no";  <---Remove this
var cookiename = "datesubmitted";


and add a function to read the cookie contents before you do anything.  Or else you will get this error to oblivion!

Follow the suggestions of my last 2 posts and you will be on your way.  If you want someone to code it for you, just post another question.
0
 

Author Comment

by:Gabrielle
ID: 6322673
Dave,

I don't know how to do what you suggest in your last two points and I need someone to do the coding for me.

If I post it as another question, would you be able to do it?

0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6322696
Yes, I could do it, but doesn't that defeat the point of actually learning how things work.  You don't have to give me points, I just want you to figure this thing out. I'm trying to help as much as possible without coding the whole thing for you.  If all you want is code, delete this question and ask a new one... no hard feelings

-Dave
0
 

Author Comment

by:Gabrielle
ID: 6326234
Dave,

I would love to learn how this works - but - at the moment I don't think I'm even at a stage where I understand the points you're trying to help me with.

I think maybe I should go off and do a bit of studying by myself for a bit and then get back to you.  Hopefully then I will understand what you're trying to tell me.

Any ideas on good tutorials/books?

0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 7910377
This question has been abandoned. I will make a recommendation to the
moderators on its resolution in a week or two. I appreciate any comments
that would help me to make a recommendation.
<note>
   In the absence of responses, I may recommend DELETE unless it is clear
   to me that it has value as a PAQ.  Silence = you don't care
</note>

Cd&
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 7999768
It is time to clean this abandoned question up.  

I am putting it on a clean up list for CS.

<recommendation>
points to Dave_Greene

</recommendation>

If anyone participating in the Q disagrees with the recommendation,
please leave a comment for the mods.

Cd&
0
 

Expert Comment

by:SpideyMod
ID: 8068008
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question