0
Needing to implement a javascript function where calculates user age, informs an alert if it is under 18.Use Jquery library along with JSP,where datepicker is automatically loaded given a framework Annotation.
Excerpt from the Code JSP
<n:panelGridBootstrap >
<t:property name="dtnascimento" />
</n:panelGridBootstrap>
Javasscript
var esteAno = new Date().getFullYear();
$("input[name='dtnascimento']").datepicker({
dateFormat: 'dd-mm-yy',
onSelect: function(date) {
var ano = date.split('-')[2]; // ano aqui
var idade = esteAno - ano;
if(idade<18){
alert("Menor de Idade");
}
What you can start to see is that you have not closed the datepicker function. There is a line missing with });
– Joao Paulo
Another thing is that you have to have referenced the jquery and used that code snippet within a $(Document) function. ready(Function(){ //here });
– Joao Paulo
Finally check for javascript error in the browser console (F12).
– Joao Paulo