[Help] Javascript for expiry date check
2014-10-26, 12:04 AM,
#1
Hi Elites,

I have a website of gift cards and cards have expiry date. I have made a javascript that compares the expiry date with todays' date and returns whether the coupon is expired or not. Script is below
Code:
<head>
    
    <script type="text/javascript">
function CompareDate() {
var x=document.getElementById("test").innerHTML;
var todayDate=new Date();
var dateOne=new Date(x);
if (todayDate > dateOne)
{
document.getElementById("test").innerHTML=" expired";
}

else
{
document.getElementById("test").innerHTML=" Not expired";
}

}

CompareDate();

</script>
</head>

<body onload="CompareDate()">
<div id="test" > 2014, 10, 24 </div>
<button type="submit" onclick="CompareDate();" > Compare</button>
</body>


Script is working fine for single id checking and returns expire or not auto. I want this procedure for all ids like test1,test2,test3... I have tried keeping the all id same as " test " but script considers for the first gift card only and for remaining nothing occurs.

Can some body guide me in right direction? Your effort would be a great help to me.Embarrassed
Reply
Share This Thread :

2014-10-26, 01:33 AM,
#2
Am not a pro coder but iyou need to loop through the ids and check them against the date.

Without iterating through all IDs, your javascript code simply terminates after checking the first id.
Reply
2014-10-26, 06:04 AM,
#3
theboogieman6 is right. You should use a
Code:
for
loop. And instead of iterating through IDs, you should use a class.

(2014-10-26, 01:33 AM)theboogieman6 Wrote: Am not a pro coder but iyou need to loop through the ids and check them against the date.

Without iterating through all IDs, your javascript code simply terminates after checking the first id.
Reply
2014-10-26, 11:59 AM,
#4
Okk I thoght the same to loop ids I will try this tnxx both of u
Reply


Related Threads
Thread Author Replies Views Last Post
  Up to date and innovative themes WealthyHustler 0 503 2017-04-25, 12:27 AM
Last Post: WealthyHustler
  [SHARE} High Quality Javascript ALERTS! Mimo 0 1,158 2016-07-11, 05:13 PM
Last Post: Mimo
  ★[Wordpress]★ Check if that downloaded theme|plugin is h@cked!★ Matt1 13 4,923 2016-01-02, 08:29 PM
Last Post: Matt1
  Anyone good with Javascript? hawdaze 6 1,020 2015-11-09, 11:43 PM
Last Post: serpkiller
  Change file size in files array with JavaScript Heka 1 506 2015-04-08, 12:14 AM
Last Post: SpawnOfdarkness





About Us | Contact Us | CPA Elites | Advertise | Stats

© 2013-2018 CPA Elites Ltd
Enhanced by MyBB and WallBB
Return to top