Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-01-2007, 09:26 PM   PM User | #1
MarkSchmetzer
New to the CF scene

 
Join Date: Feb 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
MarkSchmetzer is an unknown quantity at this point
If Then ElseIf using date ranges

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");
}
MarkSchmetzer is offline   Reply With Quote
Old 02-01-2007, 10:03 PM   PM User | #2
tonyp12
New Coder

 
Join Date: Jan 2007
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
tonyp12 has a little shameless behaviour in the past
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?

Last edited by tonyp12; 02-01-2007 at 11:40 PM..
tonyp12 is offline   Reply With Quote
Old 02-02-2007, 12:07 AM   PM User | #3
tonyp12
New Coder

 
Join Date: Jan 2007
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
tonyp12 has a little shameless behaviour in the past
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")}

Last edited by tonyp12; 02-02-2007 at 12:45 AM..
tonyp12 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:59 PM.


Advertisement
Log in to turn off these ads.