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

Thread: Max Length

  1. #1
    New Coder
    Join Date
    Jul 2010
    Posts
    67
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Max Length

    Hi there,

    Below is a code that works out the price for a hotel room in days from a weekly price. Is there anyway that I can round up to get rid of the decimals? Maybe a easier option would be to set the max length of the price? If either of these options are viable, how on earth do I do it? Sorry for the No0b question.

    PHP Code:

    // Function to calculate length of stay
    function dateDiff(dateFrom,dateTo) {
        
        
    // Set dates
          
    var datefrom dateFrom;
        var 
    dateto dateTo;
        
        if ( 
    datefrom == 'From' ) { datefrom 0; }
        if ( 
    dateto == 'To' ) { dateto 0; }
        
        
    // Changes dates so Jquery can understand them
        
    newdatefrom datefrom.replace(new RegExp("/""g"), '-');
        
    newdateto dateto.replace(new RegExp("/""g"), '-')
        
        
    // Calculate difference between dates
        
    var start = new Date(datefrom);
        var 
    end = new Date(dateto);
        var 
    diff = new Date(end start);
        var 
    days diff/1000/60/60/24;
        
        return 
    days;
        
    }

    jQuery("#datefrom").change(function () {
        
        
    // Calculate length of stay
        
    days dateDiff(jQuery(this).val(),jQuery("#dateto").val());
        
        
    // Calculate new price based on price of room
        
    var roomprice getPrice;
        
        
    // Calculate new price based on price of room and length of stay
        
    var newprice days roomprice;
        
        
    // Display new price
          
    jQuery(".room-price").text(newprice);
        
    jQuery(".price-detail-value").text(days);
        
        if ( 
    jQuery("#datefrom").val() > jQuery("#dateto").val() ) {
            
    jQuery("#datefrom").effect("pulsate", { times:}, 250);
            
    jQuery(".room-price").text("0");
            
    jQuery(".price-detail-value").text("0");
            
    //alert('The "Arrival" date cannot be after the "Departure" date');
        
    }

    }).
    keyup();

    jQuery("#dateto").change(function () {
        
        
    // Calculate length of stay
        
    days dateDiff(jQuery("#datefrom").val(),jQuery(this).val());
        
        
    // Calculate new price based on price of room
        
    var roomprice getPrice;
        
        
    // Calculate new price based on price of room and length of stay
        
    var newprice days roomprice 7;
        
        
    // Display new price
          
    jQuery(".room-price").text(newprice);
        
    jQuery(".price-detail-value").text(days);
        
        if ( 
    jQuery("#dateto").val() < jQuery("#datefrom").val() ) {
            
    jQuery("#dateto").effect("pulsate", { times:}, 250);
            
    jQuery(".room-price").text("0");
            
    jQuery(".price-detail-value").text("0");
            
    //alert('The "Departure" date cannot be before the "Arrival" date');
        
    }

    }).
    keyup(); 
    Thanks!!

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    I think Math.ceil() might do what you are looking for.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • Users who have thanked WolfShade for this post:

    joesruddock (01-30-2013)

  • #3
    New Coder
    Join Date
    Jul 2010
    Posts
    67
    Thanks
    11
    Thanked 0 Times in 0 Posts
    Perfect


  •  

    Posting Permissions

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