Jump to content

Javascript: Multiple Correct Values?


Recommended Posts

<script>
var today =new Date();
var signup = new Date( "[@authfield:Serial_Numbers_Last_Payment]" );
var renew = new Date( "[@authfield:Sheet1_Last_Payment]" );
var valid = new Date();
valid.setDate(today.getDate()-365);
if (valid<signup)
{
/*Valid*/
document.location = "http://valid-sample.com";
}
else if (valid<renew)
{
/*Valid*/
document.location = "http://valid-sample.com";
}
else
{
/*Not Valid*/
window.location = "http://invalid-sample.com"
}
</script>

Hi all,

 

I'm using this script to validate a customers annual subscription status by date.

 

It works well, except a customer may have multiple dates (in my app, when a customer buys a standalone subscription or buys a new product w/subscription this makes a timestamp in my datatable), but my script is only interrogating the first date it finds and either validates it or invalidates it.

 

Lets say a customer bought a product 3/10/2015 and then buys another product on 3/11/2016, I want the script to look at the two dates and validate the latest date (3/11/16). Currently the script only seems like it is looking at the first date (3/10/15) and invalidating the subscription because it is over 365 days old. How may I change the script to allow it to keep searching for a valid date, if there is one?

 

Thanks for the help!

 

Logan

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...