Get your CodeRanch badge!*
The moose likes HTML, CSS and JavaScript and the fly likes Validate PopUp Calendar JavaScript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Validate PopUp Calendar JavaScript" Watch "Validate PopUp Calendar JavaScript" New topic
Author

Validate PopUp Calendar JavaScript

Yessenia Arias
Greenhorn

Joined: Mar 05, 2010
Posts: 2
Hi! I have trouble validating a popup calendar, when i selected date in the calendar and put it in the field, it supose to go to validate the date isn't greater than today, but i have to click twice for do that. I am using event onBlur. I left part of code that i use. I hope someone can to help me!

function validate_f(fechaing){

var fecha = fechaing.value

var dia= fecha.split("/")[0];
var mes= fecha.split("/")[1];
var anio= fecha.split("/")[2];

var fechaactual = new Date();

var mesactual = parseInt(fechaactual.getMonth()) + 1;
var anioactual = fechaactual.getFullYear();
var diaactual = fechaactual.getDate();
if(dia>diaactual && mes==mesactual && anio==anioactual){
alert('La fecha es incorrecta');
}else{
if(dia>=diaactual && mes>mesactual && anio==anioactual){
alert('La fecha es incorrecta');
}else{
if(anio>anioactual){
alert('La fecha es incorrecta');
}
}
}
} //hasta aqui javascript

<!--html-->
<tr bgcolor="#A3BDE4">
<td>Fecha del ejercicio económico:</td>
<td>
<input name="txtFecha_inv" type="text" class="texto_fecha" id="txtFecha_inv" size="12" maxlength="12" onfocus="this.onblur()">
<a href="javascript:void(0)" onclick="if(self.gfPop)gfPop.fPopCalendar(inversion.txtFecha_inv);return false;" title="Seleccione Fecha" onblur="validate_f(inversion.txtFecha_inv);" HIDEFOCUS><img name="popcal" align="absmiddle" src="../../../imagenes/calendario.gif" border="0" alt="Seleccionar fecha"></a>
</td>
</tr>

Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Please read this UseCodeTags and edit your post.

Eric
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Your calendar code has to tell you when the selection is made. It is going to be impossible for the onblur code to fire and tell you something happened since it will fire before the calendar will put the date into the field.

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Validate PopUp Calendar JavaScript
 
Similar Threads
String date error format
How to set timer for select the time am to pm on front end in a jsp page like calender for date?
Dynamic rows validation from javascript
datetimepicker.js
help with validation/ 2 functions on submit.