Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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");
    }

  • #2
    New Coder
    Join Date
    Jan 2007
    Posts
    93
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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-02-2007 at 12:40 AM.

  • #3
    New Coder
    Join Date
    Jan 2007
    Posts
    93
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 01:45 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •