Calculate the number of days between dates and then multiply by a number

Calculate the number of days between dates and then multiply by a number

Hello,  as usual I think I am way over-thinking this, so any help pointing me in the right direction is greatly appreciated.  Ultimately I am trying to calculate the number of days between two dates and then multiply that number times another number (cost of a permit).

I am using the whatsock.com aria datepicker and have two date fields; start date and end date.

Here is where my jquery skills need serious improvement.

Each time a start and or end date field is clicked or entered, is when I need the calculations to take place.

Of my many problems is figuring out whether to use an onclick or keyup function or can I combine the two?


Below is the html
  1. https://whatsock.com/tsg/Coding Arena/ARIA Date Pickers/ARIA Date Picker (Basic)/css/customize.css
    https://whatsock.com/tsg/Coding Arena/ARIA Date Pickers/ARIA Date Picker (Basic)/css/calendar.css

    https://whatsock.com/tsg/1 AccDC API/For jQuery/Acc.DC.API.js
    https://whatsock.com/tsg/2 Accessible Component Modules/calendar_generator.js


    <li><label for="date1">Date of event:<span class="required">* </span></label><br />
                <input type="text" name="date1" id="date1" class="required" />
                <a role="button" aria-describedby="date1" href="#" id="dateIcon1" class="accCalendar datePicker"><img src="/assets/scripts/aria-datepicker/img/calendar-button.svg" alt="Calendar1" id="calendar1" title="Calendar1" /></a></li> 
                   
    <li><label for="date2">Alternate date of event:</label><br />
                <input type="text" name="date2" id="date2" />
                <a role="button" aria-describedby="date2" href="#" id="dateIcon2" class="accCalendar datePicker"><img src="/assets/scripts/aria-datepicker/img/calendar-button.svg" alt="Calendar2" title="Calendar2" /></a></li> 


        <input type="hidden" name="days" id="days" />
        <input type="hidden" name="cost" id="cost" />

The following jquery has not worked.

  1. $("#date1 , #date2").on("input", function(e) {
        var start = $('#date1').val();
        var end = $('#date2').val();
        // end - start returns difference in milliseconds
        var diff = new Date(end - start);
        // get days
        var days = diff/1000/60/60/24;   
        $("#days").val(diff*15);
    });

The jquery below does work for a basic calculation.  I was hoping to expand this, work the number of days calculation into it but have so far, failed.


  1. var $output = $("#permit_cost");
    $("#number_of_permits").on("keydown", function() {
        var value = $(this).val();
        $output.val(value*15);
    });

As I mentioned, any help is appreciated even if to let me know, "hey idiot, you forgot this!"

Peter T