Javascript??
lyn87
Messages postés
67
Date d'inscription
Statut
Membre
Dernière intervention
-
fred_bgt Messages postés 153 Date d'inscription Statut Membre Dernière intervention -
fred_bgt Messages postés 153 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
saryas
bonsoir
svp de l'aide mon code javascript ne marche pas je veux controller les champs mais mes formulaire sont generé avc une variable php voici c ke j'ai reussi à faire svp aidez moi à controller tout les champ avant la validation.
<script type="text/javascript">
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
{
alert(alerttxt);return false;
}
else
{
return true;
}
}
}
function validate_form(thisform)
{
with (thisform)
{
for ($i=0, $i<$nombre_voyageur, $i++){
if (validate_required( nom<?php $i=0; echo($i); ?>,"Veuillez saisir votre nom")==false)
{ nom<?php $i=0; echo($i) ?>.focus();return false;}
if (validate_required( prenom<?php $i=0 ; echo($i) ?>,"Veuillez saisir votre prenom!")==false)
{ prenom<?php $i=0; echo($i) ?>.focus();return false;}
if (validate_required(email<?php $i=0;echo($i)?>,"Veuillez saisir votre Email !")==false)
{email<?php $i=0; echo($i)?>.focus();return false;}
if (validate_required(tel<?php $i=0;echo($i)?>,"Veuillez SAisir le N° de téléphone!")==false)
{tel<?php $i=0;echo($i)?>.focus();return false;}
}
}
}
function verif(){
var inputList = document.forms['monFormulaire'].elements;
var alertTxt = "";
for (unInput in inputList){
if(unInput.type=="text" && unInput.value.length==0){
alertTxt += "Le champ " + unInput.name + " n'a pas été rempli \n";
}
}
alert(alertTxt);
}
</script>
<body>
<form method="post" action="reglement.php" onsubmit="verif()" >
<form method="post" action="reglement.php" onsubmit="return validate_form(this)" >
<input type="hidden" name="compteur_boucle" value="<?php echo $nombre_voyageur;?>"/>
<input type="hidden" name="adults" value="<?php echo $adults;?>"/>
<input type="hidden" name="enfants" value="<?php echo $enfants; ?>" />
<input type="hidden" name="bebe" value="<?php echo $bebe; ?>" />
<input type="hidden" name="type_vol" value="<?php echo $type_vol; ?>" />
<input type="hidden" name="aeo_depart" value="<?php echo $ville_depart; ?>" />
<input type="hidden" name="aeo_arrive" value="<?php echo $ville_arrive; ?>" />
<input type="hidden" name="date_depart" value="<?php echo $date_depart; ?>" />
<input type="hidden" name="HeureD" value="<?php echo $HeureD ; ?>" />
<input type="hidden" name="date_retour" value="<?php echo $date_retour; ?>" />
<input type="hidden" name="HeureA" value="<?php echo $data['HeureA'] ; ?>" />
<input type="hidden" name="total" value="<?php echo $total;?>"/>
<div align="center"><span class="Style6"> </span><br>
</div>
<div align="left"><br>
<br>
</div>
<table width="70%" height="289" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="3" valign="bottom" ><label></label> <span class="Style7"> <span class="Style8"> <span class="Style9"> <span class="Style10">
<label><b>Saisissez les informations voyageur</b></label>
</span> </span> </span> </span>
<label></label>
<br />
<label></label></td>
<td colspan="2" rowspan="2" valign="bottom" class="Style6">
<?php if ($enfants!=0) {echo ('Né en');}?> </td>
</tr>
<tr>
<td width="12%" height="35" valign="bottom" ><span class="Style6">Civilité</span></td>
<td width="25%" valign="bottom"><span class="Style6">Nom </span></td>
<td valign="bottom"><span class="Style6">Prénom</span></td>
</tr>
<tr>
<td height="41" ><br />
<label>
<select name="civ<?php echo($i) ?>" >
<option value="Mr">Mr</option>
<option value="Mme">Mme</option>
<option value="Mlle">Mlle</option>
</select>
</label></td>
<td width="25%" valign="bottom"><br/>
<input type="text" name="nom<?php echo($i)?>"/>
<br /> </td>
<td width="24%" valign="bottom" ><br/>
<input type="text" name="prenom<?php echo($i)?>"/>
<br/></td>
<td width="39%" class="Style3" >
<?php
$adults--;
//*******************************************Compagnons******************************************
for($i=1;$i<$nombre_voyageur;$i++)
{
if($adults!=0)
{
?> </td>
</tr>
<tr>
<td height="34" class="Style3">
<select name="civ<?php echo($i)?>" >
<option value="Mr">Mr</option>
<option value="Mme">Mme</option>
<option value="Mlle">Mlle</option>
</select> </td>
<td width="25%"><input type="text" name="nom<?php echo($i)?>"/>
<br/></td>
<td><input type="text" name="prenom<?php echo($i)?>"/>
<br /></td>
<td valign="bottom" ><?php $adults--; }
//******************************************les enfants*********************************************
elseif ($enfants!=0) { ?></td>
</tr>
<tr>
<td valign="top" ><label></label>
<p><strong>Enfant</strong></p></td>
<td width="25%" ><input type="text" name="nom<?php echo($i)?>"/>
<br /></td>
<td><input type="text" name="prenom<?php echo($i)?>"/>
<br /> </td>
<td colspan="2"><select name="an<?php echo($i)?>" >
<option value="2009">2009</option>
<option value="2008">2008</option>
<option value="2007">2007</option>
<option value="2006">2006</option>
</select> <?php $enfants--; }
//*******************************************les bebes******************************************
else { ?> <br/></td>
</tr>
<p></p>
<tr>
<td height="34" valign="top" ><strong>Bébé</strong></td>
<td><input type="text" name="nom<?php echo($i)?>2"/>
<br/></td>
<td><input type="text" name="prenom<?php echo($i)?>"/>
<br/></td>
<td colspan="2"><select name="select" >
<option value="2009">2009</option>
<option value="2008">2008</option>
<option value="2007">2007</option>
<option value="2006">2006</option>
</select> <?php
}
}
//*****************************email et numero de telephone du client*************************************
$i=0;
?> <br/></td>
</tr>
<tr>
<td> </td>
<td><strong>
<label><span class="Style3"><br />
Email </span></label>
</strong>
<label><span class="Style3"><br />
</span>
<input type="text" name="email<?php echo($i)?>"/>
</label></td>
<td colspan="3"><label><span class="Style3"><strong><br />
N° de téléphone:</strong><br />
</span>
<input type="text" name="tel<?php echo($i)?>"/>
</label></td>
</tr>
</table>
<br>
<br>
<input name="submit" type="submit" value="Réserver"/>
<br>
</form>
</div>
</body>
</html>
merci pour votre attention
cordialement
saryas
bonsoir
svp de l'aide mon code javascript ne marche pas je veux controller les champs mais mes formulaire sont generé avc une variable php voici c ke j'ai reussi à faire svp aidez moi à controller tout les champ avant la validation.
<script type="text/javascript">
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
{
alert(alerttxt);return false;
}
else
{
return true;
}
}
}
function validate_form(thisform)
{
with (thisform)
{
for ($i=0, $i<$nombre_voyageur, $i++){
if (validate_required( nom<?php $i=0; echo($i); ?>,"Veuillez saisir votre nom")==false)
{ nom<?php $i=0; echo($i) ?>.focus();return false;}
if (validate_required( prenom<?php $i=0 ; echo($i) ?>,"Veuillez saisir votre prenom!")==false)
{ prenom<?php $i=0; echo($i) ?>.focus();return false;}
if (validate_required(email<?php $i=0;echo($i)?>,"Veuillez saisir votre Email !")==false)
{email<?php $i=0; echo($i)?>.focus();return false;}
if (validate_required(tel<?php $i=0;echo($i)?>,"Veuillez SAisir le N° de téléphone!")==false)
{tel<?php $i=0;echo($i)?>.focus();return false;}
}
}
}
function verif(){
var inputList = document.forms['monFormulaire'].elements;
var alertTxt = "";
for (unInput in inputList){
if(unInput.type=="text" && unInput.value.length==0){
alertTxt += "Le champ " + unInput.name + " n'a pas été rempli \n";
}
}
alert(alertTxt);
}
</script>
<body>
<form method="post" action="reglement.php" onsubmit="verif()" >
<form method="post" action="reglement.php" onsubmit="return validate_form(this)" >
<input type="hidden" name="compteur_boucle" value="<?php echo $nombre_voyageur;?>"/>
<input type="hidden" name="adults" value="<?php echo $adults;?>"/>
<input type="hidden" name="enfants" value="<?php echo $enfants; ?>" />
<input type="hidden" name="bebe" value="<?php echo $bebe; ?>" />
<input type="hidden" name="type_vol" value="<?php echo $type_vol; ?>" />
<input type="hidden" name="aeo_depart" value="<?php echo $ville_depart; ?>" />
<input type="hidden" name="aeo_arrive" value="<?php echo $ville_arrive; ?>" />
<input type="hidden" name="date_depart" value="<?php echo $date_depart; ?>" />
<input type="hidden" name="HeureD" value="<?php echo $HeureD ; ?>" />
<input type="hidden" name="date_retour" value="<?php echo $date_retour; ?>" />
<input type="hidden" name="HeureA" value="<?php echo $data['HeureA'] ; ?>" />
<input type="hidden" name="total" value="<?php echo $total;?>"/>
<div align="center"><span class="Style6"> </span><br>
</div>
<div align="left"><br>
<br>
</div>
<table width="70%" height="289" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="3" valign="bottom" ><label></label> <span class="Style7"> <span class="Style8"> <span class="Style9"> <span class="Style10">
<label><b>Saisissez les informations voyageur</b></label>
</span> </span> </span> </span>
<label></label>
<br />
<label></label></td>
<td colspan="2" rowspan="2" valign="bottom" class="Style6">
<?php if ($enfants!=0) {echo ('Né en');}?> </td>
</tr>
<tr>
<td width="12%" height="35" valign="bottom" ><span class="Style6">Civilité</span></td>
<td width="25%" valign="bottom"><span class="Style6">Nom </span></td>
<td valign="bottom"><span class="Style6">Prénom</span></td>
</tr>
<tr>
<td height="41" ><br />
<label>
<select name="civ<?php echo($i) ?>" >
<option value="Mr">Mr</option>
<option value="Mme">Mme</option>
<option value="Mlle">Mlle</option>
</select>
</label></td>
<td width="25%" valign="bottom"><br/>
<input type="text" name="nom<?php echo($i)?>"/>
<br /> </td>
<td width="24%" valign="bottom" ><br/>
<input type="text" name="prenom<?php echo($i)?>"/>
<br/></td>
<td width="39%" class="Style3" >
<?php
$adults--;
//*******************************************Compagnons******************************************
for($i=1;$i<$nombre_voyageur;$i++)
{
if($adults!=0)
{
?> </td>
</tr>
<tr>
<td height="34" class="Style3">
<select name="civ<?php echo($i)?>" >
<option value="Mr">Mr</option>
<option value="Mme">Mme</option>
<option value="Mlle">Mlle</option>
</select> </td>
<td width="25%"><input type="text" name="nom<?php echo($i)?>"/>
<br/></td>
<td><input type="text" name="prenom<?php echo($i)?>"/>
<br /></td>
<td valign="bottom" ><?php $adults--; }
//******************************************les enfants*********************************************
elseif ($enfants!=0) { ?></td>
</tr>
<tr>
<td valign="top" ><label></label>
<p><strong>Enfant</strong></p></td>
<td width="25%" ><input type="text" name="nom<?php echo($i)?>"/>
<br /></td>
<td><input type="text" name="prenom<?php echo($i)?>"/>
<br /> </td>
<td colspan="2"><select name="an<?php echo($i)?>" >
<option value="2009">2009</option>
<option value="2008">2008</option>
<option value="2007">2007</option>
<option value="2006">2006</option>
</select> <?php $enfants--; }
//*******************************************les bebes******************************************
else { ?> <br/></td>
</tr>
<p></p>
<tr>
<td height="34" valign="top" ><strong>Bébé</strong></td>
<td><input type="text" name="nom<?php echo($i)?>2"/>
<br/></td>
<td><input type="text" name="prenom<?php echo($i)?>"/>
<br/></td>
<td colspan="2"><select name="select" >
<option value="2009">2009</option>
<option value="2008">2008</option>
<option value="2007">2007</option>
<option value="2006">2006</option>
</select> <?php
}
}
//*****************************email et numero de telephone du client*************************************
$i=0;
?> <br/></td>
</tr>
<tr>
<td> </td>
<td><strong>
<label><span class="Style3"><br />
Email </span></label>
</strong>
<label><span class="Style3"><br />
</span>
<input type="text" name="email<?php echo($i)?>"/>
</label></td>
<td colspan="3"><label><span class="Style3"><strong><br />
N° de téléphone:</strong><br />
</span>
<input type="text" name="tel<?php echo($i)?>"/>
</label></td>
</tr>
</table>
<br>
<br>
<input name="submit" type="submit" value="Réserver"/>
<br>
</form>
</div>
</body>
</html>
merci pour votre attention
cordialement
1 réponse
Moi je ne lis même pas un code aussi mal mis en page et bourré de fautes.
Désolé. Mais lire autant de lignes mal structurées, c'est une perte de temps inutile. Je te conseille d'aborder la programmation avec plus de rigueur.
ex:
<tr>
<td> </td>
<td><strong>
<label><span class="Style3"><br />
Email </span></label>
</strong>
<label><span class="Style3"><br />
</span>
<input type="text" name="email<?php echo($i)?>"/>
</label></td>
<td colspan="3"><label><span class="Style3"><strong><br />
N° de téléphone:</strong><br />
</span>
<input type="text" name="tel<?php echo($i)?>"/>
</label></td>
</tr>
C'est illisible !!!
<tr>
<td></td>
<td>
<label><span class="Style3"><br /><b>Email </b></span></label>
<label><span class="Style3"><br /></span><input type="text" name="email <?php echo($i)?>"/<label></td>
<td colspan="3"><label><span class="Style3"><strong><br />N° de téléphone:</strong><br /></span>
<input type="text" name="tel<?php echo($i)?>"/></label></td>
</tr>
C'est mieux ...
Désolé. Mais lire autant de lignes mal structurées, c'est une perte de temps inutile. Je te conseille d'aborder la programmation avec plus de rigueur.
ex:
<tr>
<td> </td>
<td><strong>
<label><span class="Style3"><br />
Email </span></label>
</strong>
<label><span class="Style3"><br />
</span>
<input type="text" name="email<?php echo($i)?>"/>
</label></td>
<td colspan="3"><label><span class="Style3"><strong><br />
N° de téléphone:</strong><br />
</span>
<input type="text" name="tel<?php echo($i)?>"/>
</label></td>
</tr>
C'est illisible !!!
<tr>
<td></td>
<td>
<label><span class="Style3"><br /><b>Email </b></span></label>
<label><span class="Style3"><br /></span><input type="text" name="email <?php echo($i)?>"/<label></td>
<td colspan="3"><label><span class="Style3"><strong><br />N° de téléphone:</strong><br /></span>
<input type="text" name="tel<?php echo($i)?>"/></label></td>
</tr>
C'est mieux ...