Buy Now
Sign in

Javascript don't work on my text field

hilmata , October 14 2019, 10:29
H
hilmata 24
October 14 2019, 10:29 #389550
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?
Capture1.PNG
Capture2.PNG
Capture3.PNG
javascript57
jQuery.fn.form.settings.rules.verifnaissance = function(value, param) {

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;
}

};
javascript59
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;
}

};
GreyHead 64
October 14 2019, 10:54 #389552
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
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
H
hilmata 24
October 14 2019, 11:16 #389554
OK. http://pjfe.dncmp-togo.com/#sp-header-appointment
thanks for the quick reply
The content here is visible only for authorized users.
healyhatman 8
October 14 2019, 11:58 #389555
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.
Web developer at SkySpider.com.au - I DO NOT work for ChronoEngine!
Donations: paypal.me/healyhatman
Professional Work: kamron@skyspider.com.au
Custom CF / CC Plugins and Extensions: skyspider.com.au/store
H
hilmata 24
October 14 2019, 12:04 #389557
yes but the problem is that the age limit of 40 is just applied to men
H
hilmata 24
October 15 2019, 09:22 #389567
so how am I going to enter the "Earliest date / time" parameter of the calendar field so that it only applies when sex = M ?
healyhatman 8
October 15 2019, 14:59 #389572
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.
Web developer at SkySpider.com.au - I DO NOT work for ChronoEngine!
Donations: paypal.me/healyhatman
Professional Work: kamron@skyspider.com.au
Custom CF / CC Plugins and Extensions: skyspider.com.au/store
H
hilmata 24
October 15 2019, 15:44 #389575
Thank you. I will try and make you a return.
H
hilmata 24
October 16 2019, 11:22 #389594
 1
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!!
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;
}

};