Fonction JavaScript ne s'exécute qu'une seconde
Bonjour à tous,
j'ai créé une fonction javascript pour vérifier la pertinence de mes champs. Les champs se colorent en rouge s'ils sont erronés mais la couleur disparait au bout d'une seconde et le message d'alerte ne s'affiche pas
fonction javascript :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| // Vérification de la pertinence des champs
function verifierCreerFAJ()
{
var erreur=0;
for(var i=0;i<10;i++)
{
var inputNomSel=[];
var inputFajSel=[];
inputNomSel[i]=document.forms["formCreerFAJ"].elements["substance["+i+"]"].value;
inputFajSel[i]=document.forms["formCreerFAJ"].elements["faj["+i+"]"].value;
if( (inputNomSel[i]==="" && inputFajSel[i]!=="") || (inputNomSel[i]==="Substance "+i && inputFajSel[i]!=="") )
{
document.forms["formCreerFAJ"].elements["substance["+i+"]"].style.backgroundColor = "#FF0000";
erreur++;
}
else
{
inputNomSel.innerHTML=document.forms["formCreerFAJ"].elements["substance["+i+"]"].value;
document.forms["formCreerFAJ"].elements["substance["+i+"]"].style.backgroundColor = "#FFFFFF";
}
}
if(erreur===0)
{
return (true);
}
else
{
alert("Certains champs sont incomplets ou erronés");
return (false);
}
} |
code HTML / php
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| echo'<form id="formCreerFAJ" action="" method="POST" onsubmit="return verifierCreerFAJ();">'."\n";
echo' <table class="faj1">'."\n";
echo' <caption>Stock de sels de métaux précieux</caption>'."\n";
echo' <thead bgcolor="'.$tableau20['couleurFAJ'].'">'."\n";
echo' <tr>'."\n";
echo' <th rowspan="2" class="sel">Sel</th>'."\n";
echo' <th colspan="4">Pré-coffre (kg)</th>'."\n";
echo' <th colspan="4">Consigne (kg)</th>'."\n";
echo' <th colspan="4">Coffre (kg)</th>'."\n";
echo' <th rowspan="2">Total (kg)</th>'."\n";
echo' </tr>'."\n";
echo' <tr>'."\n";
echo' <th>J-1</th>'."\n";
echo' <th>Entrées</th>'."\n";
echo' <th>Sorties</th>'."\n";
echo' <th>Total</th>'."\n";
echo' <th>J-1</th>'."\n";
echo' <th>Entrées</th>'."\n";
echo' <th>Sorties</th>'."\n";
echo' <th>Total</th>'."\n";
echo' <th>J-1</th>'."\n";
echo' <th>Entrées</th>'."\n";
echo' <th>Sorties</th>'."\n";
echo' <th>Total</th>'."\n";
echo' </tr>'."\n";
echo' </thead>'."\n";
echo' <tbody bgcolor="'.$tableau20['couleurFAJ'].'">'."\n";
$nbColonnes=13;
for($i=0;$i<5;$i++)
{
echo' <tr>'."\n";
echo' <td><input type="text" name="substance['.$i.']" id="substance['.$i.']" value="Substance '.$i.'" size="12" maxlength="20" />'."\n";
echo' <select name="faj['.$i.']" id="faj['.$i.']">'."\n";
echo' <option value=""></option>'."\n";
$txtRequete11='SELECT * FROM substancefaj WHERE idFAJ="1" OR idFAJ="2" OR idFAJ="3" OR idFAJ="5" ORDER BY idFAJ';
$requete11=mysql_query($txtRequete11);
while($tableau11=mysql_fetch_assoc($requete11))
{
echo' <option value="'.$tableau11['idFAJ'].'">'.$tableau11['compositionPrincipaleFAJ'].'</option>'."\n";
}
echo' </select>'."\n";
echo' </td>'."\n";
/*******************************************************************************************/
for($j=0;$j<$nbColonnes;$j++)
{
echo' <td></td>'."\n";
}
echo' </tr>'."\n";
}
echo' </tbody>'."\n";
echo' </table>'."\n";
// Création du formulaire de validation de faj1
echo' <table class="formSimple">'."\n";
echo' <tr>'."\n";
echo' <td><input type="submit" value="Valider" name="valider0" /></td>'."\n";
echo' <td><input type="reset" value="Effacer" name="effacer" /></td>'."\n";
echo' </tr>'."\n";
echo' </table>'."\n";
echo' <input type="hidden" name="idMetal" value="'.$_POST['idMetal'].'" />'."\n";
echo'</form>'."\n"; |
Pourriez vous m'aider ?
Merci d'avance