Hopeing that someone can help me out here. I have a form where I need a user to input a start time and the end time of an incident. Once they have input the information they would manually enter the duration between the 2 date time. I am trying to automate this process with jquery and got an addon called moments http://momentjs.com/. I was hoping that it would make it simpler for me to calculate 2 date times but i gotta admit im not much of a savvy with jquery of javascript to understand how its suppose to come together.
On a side note as well I needed the duration field to be only calculated if its empty. I created a jsfiddle http://jsfiddle.net/FLhpq/2044/. This would be the closest i could get to replicate my scenario. Here is the code I had so far.
$(document).ready(function() {
var start_time = $('input[title="start time"]').val();
var end_time = $('input[title="End time"]').val();
var d1 = moment(start_time, "YYYY-MM-DD HH:mm");
var d2 = moment(end_time, "YYYY-MM-DD HH:mm");
var duration = d2.diff(d1, 'hours')+1;
var input = $('input[title="duration"]').val();
if(input == ''){
$('#duration').val('duration');
});