I am not able to validate form, there is two fields in my form, one is select dropdown, and one is datepicker.
I want when someone select urgent Processing in select dropdown and they select their date of journey between 5 days from today, form should show a message "For travel within next 5 days please select Urgent Processing in the Application Type. With normal Processing you can only travel after 5 day" and prevent submit. but it seems not to working. Where I am wrong here?
<form name="search_form" method="post" onSubmit="onSubmit="return chk();" action="applyprocess.php" autocomplete="off">
<select name="applicationtype" class="textBoxDashed" id="applicationtype" onChange="myFunction(this)" required>
<option value="">Select..</option>
<option data-price="69" value="Normal Processing">Normal Processing (Processing Time 4 to 7 Business days)</option>
<option data-price="189" value="Urgent Processing">Urgent Processing (Processing Time 1 Business Day) </option>
</select>
<input name="journeydate" id="journeydate" placeholder="DD/MM/YYYY" datepicker_format="DD/MM/YYYY" class="textBoxDashed" size="43" title="Please Enter your Date of Journey" required readonly>
<input name="button" type="submit" class="btn btn-primary" value="Continue">
</form>
This is form validation script
<script language="javascript">
if (trim(document.search_form.journeydate.value)==''){
alert("Please Enter Valid Journey Date ");
document.search_form.journeydate.focus();
return false;
}
var today = new Date();
var dd = today.getDate()+1;
var mm = today.getMonth()+1;//January is 0!`
var yyyy = today.getFullYear();
if(dd<10){dd='0'+dd}
if(mm<10){mm='0'+mm}
var todayDate = dd+'../https/websitedownloaderio/MS_8.html'+mm+'/'+yyyy;
var number13 = Number(dd);
var monthNumber = Number(mm);
var yearNumber = Number(yyyy);
var currentDays = (monthNumber*30)+number13;
var jDate = document.search_form.journeydate.value;
var dd2 = jDate.slice(0,2);
var number12 = Number(dd2);
var mon2 = jDate.slice(3,5);
var yr2 = jDate.slice(6,10);
var monthNumber2= Number(mon2);
var yearNumber2 = Number(yr2);
var journeyDays = (monthNumber2*30)+number12;
if(number12>number13){
number12 = number12+30;
monthNumber2 = monthNumber2-1;
}
if(monthNumber2>monthNumber){
monthNumber2 = monthNumber2+12;
monthNumber2 = monthNumber2-1;
}
if(yearNumber2>yearNumber){
yearNumber2 = yearNumber2-yearNumber;
}
var finalDays = ((yr2-yyyy)*360)+((mon2-mm)*30)+(dd2-dd);
if(trim(document.search_form.applicationtype.value)=='Normal Processing' && finalDays<=5)
{
alert("For travel within next 5 days please select Urgent Processing in the Application Type. With normal Processing you can only travel after 5 day.");
document.search_form.applicationtype.focus();
return false;
}
if(trim(document.search_form.applicationtype.value)=='Urgent Processing' && finalDays>=30)
{
alert("Please select normal processing from the drop down because your arrival date is beyond 30 days.");
document.search_form.applicationtype.focus();
return false;
}
</script>
This is what I am using for datepicker:
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$( function() {
$( "#journeydate" ).datepicker({
yearRange: '2018:2028',
changeMonth: true,
changeYear: true,
dateFormat: 'yy-mm-dd',
minDate: +1
});
} );
</script>