Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Validate PopUp Calendar JavaScript

 
Yessenia Arias
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read this UseCodeTags and edit your post.

Eric
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic