Scrolling vers un champ vide apres validation
Bonjour à tous, je viens demander de l'aide pour la 3ème fois de la semaine (ce jquery me pose pas mal de prob decidement :mrgreen: ) j'ai actuellement un soucis sur ma fonction dont le but et de scroller vers le champ vide détecté apres validation d'un formulaire.
La partie detection se passe bien j'ai fait un test et je recupère aussi correctement la hauteur de mon id mais le scrolling ne se fait pas.Cela doit provenir d'interaction entre les different element de ma fonction mais je ne vois pas comment...:weird:
Voici la fonction en jquery:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| jQuery(function($) {
$('#form').live("submit", function(){
if ($.trim($("#initiateur").val()).length == 0) { //test une chaine sans caractère plutot qu'un champ vide pour
alert('champ ini vide'); //eviter de considérer les espace ou les retour a la ligne.
$('#initiateur').focus();
$('#initiateur').css('border-color','#8a1f11');
hauteur=$('#initiateur').offset().top;
$('html,body').animate({scrollTop:hauteur},1000); //on recupere la hauteur de l'id
return false;
};
$('#changement').val();
if ($.trim($("#changement").val()).length == 0) {
alert('champ changement vide');
return false;
};
});
//partie datepicker
$('#datecreation, #datedebut, #datefin').datepicker({
dateFormat : 'yy-mm-dd' //permet a la bdd d'interpréter comme format date!
});
}) |
et voici le code html:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| <form action="verif_modif.php" method="POST" id="form" >
<table class="ombrage" border="0" cellspacing='0' cellpadding='0' width="90%;" style="box-shadow:2px 2px 4px black;" >
<tr>
<td class="colonne1" ><strong>Initiateur : </strong></td>
<td class="colonne_colspan" colspan="2" >
<textarea type="text" name="ini" id="initiateur" rows="5" cols="50" ><?php echo $data['initiateur']; ?></textarea>
</td>
</tr>
<tr>
<td class="colonne1" ><strong>Changement : </strong></td>
<td class="colonne_colspan" colspan="2" >
<textarea type="text" name="changement" id="changement" rows="5" cols="50" ><?php echo $data['changement']; ?> </textarea>
</td>
</tr>
<tr>
<td style="padding-bottom:8px;" colspan="3" class="validation">
<center><INPUT border="0" src="images/bouton_validation.png" type="image" Value="submit" ></center>
</td>
</tr> |