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 01-30-2013, 02:36 PM   PM User | #1
joesruddock
New Coder

 
Join Date: Jul 2010
Posts: 65
Thanks: 11
Thanked 0 Times in 0 Posts
joesruddock is an unknown quantity at this point
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!!
joesruddock is offline   Reply With Quote
Old 01-30-2013, 03:04 PM   PM User | #2
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 960
Thanks: 7
Thanked 100 Times in 100 Posts
WolfShade is an unknown quantity at this point
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".
WolfShade is offline   Reply With Quote
Users who have thanked WolfShade for this post:
joesruddock (01-30-2013)
Old 01-30-2013, 03:23 PM   PM User | #3
joesruddock
New Coder

 
Join Date: Jul 2010
Posts: 65
Thanks: 11
Thanked 0 Times in 0 Posts
joesruddock is an unknown quantity at this point
Perfect
joesruddock 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 12:21 PM.


Advertisement
Log in to turn off these ads.