Hi. I have my text field that I formatted so that we can fill in the dates of birth. I then put javascript codes to avoid the errors of seizures and that the men of more than 40 years are registered. At first it worked well but now, nothing. On the other hand locally it works. Can you help me please?
[file=12306]Capture1.PNG[/file]



javascript57
[file=12306]Capture1.PNG[/file]
javascript57
jQuery.fn.form.settings.rules.verifnaissance = function(value, param) {javascript59
var dateNow = new Date();
var currentYear = dateNow.getFullYear();
strSaisie = value.replace(/-/g,"");
var yearSaisie = Number(strSaisie.substr(4,4));
if(document.getElementById('sex0').checked){
var valeur = document.getElementById('sex0').value;
} else{
if(document.getElementById('sex1').checked){
var valeur = document.getElementById('sex1').value;
}
}
if(valeur != null && yearSaisie ==0) {
return true;
}
if ((currentYear - yearSaisie)<18 || ((valeur == 'M') && (currentYear - yearSaisie) > 40)) {
return false;
}else{
return true;
}
};
jQuery.fn.form.settings.rules.verifNaN = function(value, param) {
str = value.replace(/-/g,"");
var year = str.substr(7,1);
if( year == 'y') {
return false;
}else{
return true;
}
};
Hi hilmata,
Sounds like a JavaScript error from something else on the page. Please post a link to the form so we can take a quick look.
Bob
Sounds like a JavaScript error from something else on the page. Please post a link to the form so we can take a quick look.
Bob
OK. http://pjfe.dncmp-togo.com/#sp-header-appointment
thanks for the quick reply
thanks for the quick reply
This is private content
Can you not just use a calendar field, set to Date, with the earlier time set to {date:Y-m-d$-40 years} and the latest date set to {date:Y-m-d$-18 years} ? That will only let you select birth days 18-40 years ago.
so how am I going to enter the "Earliest date / time" parameter of the calendar field so that it only applies when sex = M ?
Have two calendars, with different IDs. use #id to show/enable or hide/disable one field and the opposite for the other, so you have one field with the male rules and one without, and they hide/show depending on which sex you choose. That's one option.
Hello!!! I come with good news!! finally, I retouched ma javascript code I it started to work again.
there is the new contents of my javascript57. I used document.querySelector instead of document.getElementById/ByName to get the value of the date. Thank you!!
there is the new contents of my javascript57. I used document.querySelector instead of document.getElementById/ByName to get the value of the date. Thank you!!
jQuery.fn.form.settings.rules.verifnaissance = function(value, param) {
var dateNow = new Date();
var currentYear = dateNow.getFullYear();
var dateNow = new Date();
var currentYear = dateNow.getFullYear();
var strSaisie = document.querySelector("#date_naissance").value.replace(/-/g,"");
var yearSaisie = Number(strSaisie.substr(4,4));
valeur = (document.querySelector('input[name="sexe"]:checked').value);
if(valeur != null && yearSaisie ==0) {
return true;
}
if ((currentYear - yearSaisie)<18 || ((valeur == 'M') && (currentYear - yearSaisie) > 40)) {
return false;
}else{
return true;
}
};
This topic is locked and no more replies can be posted.