...

View Full Version : If Then ElseIf using date ranges



MarkSchmetzer
02-01-2007, 10:26 PM
I would appreciate any help I can get. I want to have var changed based on the date. I can get it to work with one date, but when IU want the different values for between dates, it fails.

Example is if date is <= 3/27, then a = 35
elseif date is between 3/28 & 4/6, then a = 40
else registration over.

var today = new Date();

var todaym = today.getMonth();
var todayd = today.getDate();

function calc() {

if (todaym <= 3 && todayd <= 21) {
a = document.form1.a.value;
b = a*35.00;
document.form1.total1.value = b
a0 = document.form1.a0.value;
c = a0*10.00;
document.form1.total2.value = c
a1 = document.form1.a1.value;
d = a1*10.00;
document.form1.total3.value = d
a2 = document.form1.a2.value;
e = a2*35.00;
document.form1.total4.value = e
f = b + c + d + e;
document.form1.total5.value = f;
}

else alert ("Registration closed, please register at the tournament");
}

tonyp12
02-01-2007, 11:03 PM
start with adding +1 to month
as the date object uses 0-11 month

var todaym = today.getMonth()+1;


But what about 2/25? your if statment will not allow early reg discount for this date.
if (todaym <= 3 && todayd <= 21 || todaym <= 2 )

And should you not check date if online registration is closed before the user
even are allowed to input number of tickets and the ticket type?
Why waste their time to alert after they try to get total.

You could disable the submit button or hide the whole form with a hidden div.

Any why not populate the value specific to the date with a onLoad so the user know the price before selecting a ticket?

tonyp12
02-02-2007, 01:07 AM
That is why it's good to use the number of milliseconds since midnight Jan 1, 1970

var duedate = Date.parse("Mar 21, 2007, 23:59:59"); // to midnight including Mar 21
var today= new Date();
if (today.getTime() < duedate) {
}
else { alert("to late")}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum