Javascript Date Validation

Ri Ripei 24 Dec, 2009
Hey Guys

I know, there are already dozends of similar issues out there but i havn't been able to solve my problem. I do have a form where also 3 dropdown-selection-boxes are included. They are used for the birthday of the person who signs the form. 1 box for year, another for month and the third for day.
My aim is to make a javascript validation of these boxes... these boxes should only be valid when the person is older than e.g. 13th May of 1990.

Is it possible to make such an javascript validation. Up to now i wasn't able to figur out how i can add an own javascript-validation rule.

Thanks for your help... and guys; i wish you a blessed xmas🙂
Ripei
Gr GreyHead 24 Dec, 2009
Hi ripei,

What are you actually trying to check here. If you add a JavaScript data validation then there is nothing to stop the user changing the date so that it validates. You'd have more control doing the validation after submission.

That said, it shouldn't be too hard to write a custom LiveValidation for this, but it's not something that I can do in 5 minutes on Xmas eve :-(

Bob
Ri Ripei 25 Dec, 2009
Hey Bob

Thanks for your thoughts... you're basically right... there is nothing what could stop the user from inputing wrong data. (but i am allowed to asume, that the person enters its real birthdates). the reason why i want to use javascript is that i am using a ajax tab navigation for the whole navigation of my homepage (gavick tabs manager). in one of these tabs is the form... and if i would use the server side validation the error code does appear above the ajax tab navigation... and this destroys my whole homepage-layout.

so there are two possible solutions:
1. i use javascript validation
2. the server side validation error text would appear in an pop up.

could you probably give me some hints how to maintain the javasricpt validation?!
lg raphi
SP SPABO 16 Apr, 2010
Dear Ripei
I was wondering if you found the answer, I'm struggling with the same problem, however in my case it should calculate the days between the selected date and the date of submission
I made this in the servide validation, whatever I do, I'm always "too late"😟
<?php
$date1 = new DateTime(JRequest::getVar('Wedstrijddatum', '', 'Wedstrijddatum'));
// this should be the selected date
$date2 = $date; //this should be today
if((($date1-$date2))>28) { // 28 is number of days
$ok = false; 
        return '- Too early to subscribe!.<br />'; //too earlie
 } 
if((($date1-$date2))<5*3600*24) { //5 is number of days
 $ok = false; 
        return '- Too late to subscribe!.<br />';//too late
 } 
?>

Any thoughts on this?
This topic is locked and no more replies can be posted.