oninput JavaScript Date Function Calculator
11:09 09 Oct 2014

I found this code online and am unable to get it to work correctly can someone please tell me where I am going wrong? The description made it sound like it will work exactly how I need it to but for some reason I cannot get it to work correctly on my end. I have been putting a bunch of alerts and cannot even get them to display. I am sorry I am very new trying to teach myself JavaScript.

Input button:


JavaScript Function:

function getDatePrice(date) {
    var datePrice = 0
    var theForm = document.forms["form"];
    var purchasedate = theForm.elements["purchasedate"];
    var date = new Date(purchasedate.value);
if (Object.prototype.toString.call(date) !== '[object Date]') {
        date = new Date();
    }
var today = new Date();
    var diffMilli = today - date;
    var diffDays = diffMilli * 1000 * 60 * 60 * 24;

    if (diffDays > 30) {
        datePrice= 20;
    }
    return datePrice;
}

function calculateTotal()
{
    var titleFees =  getDatePrice(date);
    var divobj = document.getElementById('totalPrice');
    divobj.style.display='block';
    divobj.innerHTML = "Estimated Transfer Fees $"+titleFees;

}
javascript