$("#startdate").datepicker({altField: '#start_alternate',altFormat: 'yy-mm-dd',minDate: '-1y',maxDate: -1}); $("#enddate").datepicker({altField: '#end_alternate',altFormat: 'yy-mm-dd',minDate: '-1y',maxDate: -1}); $('button#selectDateRange').click(function(){ $('#dialog').dialog('open'); }); $('#dialog').dialog({ autoOpen: false, width: 400, modal: true, resizable: false, close: function() { $('#message').html(""); $('#dateRangeForm :input').each(function() { $(this).val(''); }); }, buttons: { "Close": function() { $(this).dialog("close"); $('#message').html(""); $('#dateRangeForm :input').each(function() { $(this).val(''); }); }, "Submit": function() { var errors = 0; $('#dateRangeForm :input').each(function() { if($(this).val() == ''){ $(this).prev().prev().css("color", "red"); $(this).prev().val('Click box and use calendar to enter date.'); errors++; } else { $(this).prev().css("color", "black"); } }); if (errors == 0){ dataString = $('form').serialize(); $.ajax({ type: "POST", url: "dateRange.php", data: dataString, dataType: "json", success: function(data) { if(data.error == "invalid"){ $('#message').html("
Date range is invalid.
"); } else { $('#message').html("
Date range is valid.
"); } } //end of success }); //end of ajax } //end of if(errors == 0) } //end of Submit button function } //end of buttons: }); //end of dialog