Hello,
I used the following javascript code to apply a validation to a date field called Date of Birth, found in a collection. I created a css class called "dateofbirth".
//----------------------------------Performs code on load-------------------------------- var todaysDate = new Date(); // Gets today's date //Max date attribute is in "YYYY-MM-DD". Need to format today's date accordingly var dob_year = todaysDate.getFullYear()-18; //var dob_year = todaysDate.getFullYear(); // YYYY var dob_month = ("0" + (todaysDate.getMonth() + 1)).slice(-2); // MM var dob_day = ("0" + todaysDate.getDate()).slice(-2); // DD var dob_maxDate = (dob_year +"-"+ dob_month +"-"+ dob_day); // Results in "YYYY-MM-DD" for today's date // Now to set the max date value for the calendar to be today's date $('.dateofbirth input').attr('max',dob_maxDate); $('#q53 > a').on('click',function() { //-----------------------Performs code when add button is clicked------------------------ var todaysDate = new Date(); // Gets today's date //Max date attribute is in "YYYY-MM-DD". Need to format today's date accordingly var dob_year = todaysDate.getFullYear()-18; //var dob_year = todaysDate.getFullYear(); // YYYY var dob_month = ("0" + (todaysDate.getMonth() + 1)).slice(-2); // MM var dob_day = ("0" + todaysDate.getDate()).slice(-2); // DD var dob_maxDate = (dob_year +"-"+ dob_month +"-"+ dob_day); // Results in "YYYY-MM-DD" for today's date // Now to set the max date value for the calendar to be today's date $('.dateofbirth input').attr('max',dob_maxDate); });
The code works perfectly in preview mode (means the ID used are correct). But when I published the form and tests it in an external link, it doesn't work in the second item of the collection.
Note that we have a forms server in DMZ, used to publish forms over the internet. We are able to submit our form successfully.
Please advise.
Best regards,