I am working on a website (new to web development) and I am having an issue with the following code(setting the end date to tomorrow if it is blank):
var date = new Date($('#txtStartDate').val());
var tomorrow = date.getDate() + 1;
$('#txtEndDate').val(tomorrow);
Later in the same function
var myObj = {StartDate: $('#txtStartDate').val(), EndDate: $('#txtEndDate').val() };
I am using MVC 5 and when the object hits the controller the start date is set but the end date is still null (also using visual studio 2013 update 1 so debugging is broken since the js is in the cshtml file).
From searching, the code should work unless I have a mistake I am not seeing.
EDIT:
Well after finding a way to debug my code I found that $('#txtStartDate').val() was returning just mm/dd/yyyy and not providing the correct date. That is fixed. As far as not checking for the end date being null, there are 2 different conditions on the form where an end date could be null. For one I need to set the end date to be the next day from the start date, for another a null end date is perfectly valid.