Hi
Here part of my form:
<div class="cred-field cred-field-date-join" >
<label class="cred-label">
Enter the first day you will come to accommodation<font color="red">*</font> (it should be on [types field='first-day-of-semester' style='text' format='F j, Y' id="643"][/types] or AFTER)
</label>
[cred_field field='date-join' post='booking' value='[wpv-post-today]' urlparam='']
</div>
[wpv-conditional if="( '[types usermeta="gu-student" user_current="true"][/types]' eq 'No' )"]
<div class="cred-field cred-field-booking-departure-date" >
<label class="cred-label">
Your departure date
</label>
[cred_field field='booking-departure-date' post='booking' value='' urlparam='']
</div>
[/wpv-conditional]
[wpv-conditional if="( '[types usermeta="gu-student" user_current="true"][/types]' eq 'Yes' )"]
<div class="cred-field cred-field-booking-contract-type">
<label class="cred-label">
You want to rent a room until...<font color="red">*</font> Check the semester rental and annual rental hidden link" target="_blank">HERE
.
</label>
[cred_field field='booking-contract-type' post='booking' value='' urlparam='']
</div>
[cred_show_group if="($(booking-contract-type) eq '4')" mode="fade-slide"]
<font color="red">You will have to checkout 20 weeks after your arrival date </font>
[/cred_show_group]
[cred_show_group if="($(booking-contract-type) eq '8')" mode="fade-slide"]
<font color="red">You will have to checkout 40 weeks after your arrival date </font>
[/cred_show_group]
[/wpv-conditional]
<p hidden id='semesterstartdate'>[types field='first-day-of-semester' style='text' format='F j, Y' id='643'][/types] </p>
and here my JS (problematic code is commented):
jQuery(document).ready(function($){
var x = $('#semesterstartdate').text();
var d = Date.parse(x);
from = jQuery('input[name="wpcf-date-join[display-only]"').attr('id');
to = jQuery('input[name="wpcf-booking-departure-date[display-only]"').attr('id');
$( "#"+from ).on('change',function(){
//first code
//var e = document.getElementsByName("wpcf-booking-contract-type");
//var aa = e.options[e.selectedIndex].value;
//second code
//var e = document.getElementById("cred_form_6910_1-select-1-1534010971");
//var aa = e.options[e.selectedIndex].text;
// window.alert("aa");
if($( "#"+from ).val() !=''){
$('.cred-field-date-join .js-wpt-date-clear').show();
}else{
$('.cred-field-date-join .js-wpt-date-clear').hide();
}
});
$( "#"+to ).on('change',function(){
if($( "#"+to ).val() !=''){
$('.cred-field-booking-departure-date .js-wpt-date-clear').show();
}else{
$('.cred-field-booking-departure-date .js-wpt-date-clear').hide();
}
});
$( "#"+from ).datepicker({
changeMonth: true,
changeYear: true,
minDate: new Date(d),
onClose: function( selectedDate ) {
$( "#"+to ).datepicker( "option", "minDate", selectedDate );
}
});
$( "#"+to ).datepicker({
changeMonth: true,
changeYear: true,
minDate: 0,
onClose: function( selectedDate ) {
$( "#"+from ).datepicker( "option", "maxDate", selectedDate );
}
});
$("form.cred-form").on("submit", function(e){
if ($('form.cred-form').valid()) {
$('input.wpt-form-submit').hide();
$("cc").text("Submitting... please wait...");
} else {
$("input.wpt-form-submit").show();
}
});
});
window.onunload = refreshParent;
function refreshParent() {
window.opener.location.reload();
}
In JS, I tried "first code" and "second code", but both did not work.
Thank you