Solved

Could someone please add an expiry date to this cookie?

Posted on 2001-07-17
45
301 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
Comment Utility
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
Comment Utility

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
Comment Utility
My typo :-(

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

e should've been an y...my mistake.
0
 

Author Comment

by:Gabrielle
Comment Utility

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
Comment Utility
Check your browser-cache
0
 
LVL 9

Expert Comment

by:msdixon
Comment Utility
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
Comment Utility
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
Comment Utility

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
Comment Utility
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
Comment Utility
The order of the calls is incorrect..
0
 
LVL 8

Expert Comment

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

ExpireDate = Date();
0
 

Author Comment

by:Gabrielle
Comment Utility

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
Comment Utility

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
Comment Utility
today      = new Date();

sorry :-/
0
 
LVL 8

Expert Comment

by:Dave_Greene
Comment Utility
Pretty sure you do not need the "NEW" keyword...
0
 

Author Comment

by:Gabrielle
Comment Utility
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
Comment Utility
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
Comment Utility

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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:Gabrielle
Comment Utility
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
Comment Utility
Have you dimensioned ExpireDate?

Dim ExpireDate
0
 

Author Comment

by:Gabrielle
Comment Utility
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
Comment Utility
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
Comment Utility

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
Comment Utility
Just out of curiousity, you have your browser set to accept cookies, correct?
0
 

Author Comment

by:Gabrielle
Comment Utility


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

Expert Comment

by:Dave_Greene
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now