script qui ne fonctionne pas
bonjour,
pourquoi mon script ne fonctionne pas (la detection des champs vides ne se fait pas) ?
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
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
<head>
<title>TEST</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">
// <![CDATA[
function lance_verif(){
var alertTxt = "";
var listElements = document.getElementById("myForm").getElementsByTagName('input');
for (myElement in listElements){
if (myElement.type == "text" ){
if (myElement.value.length == 0){
alertTxt += "Le champ " + myElement.id + " n'a pas été rempli \n";
document.getElementById(myElement.id + "_erreur").innerHTML = "erreur";
} else {
document.getElementById(myElement.id + "_erreur").innerHTML = "";
}
}
}
if (alertTxt.length != 0){
alert(alertTxt);
} else {
// appel de la page php
}
}
// ]]>
</script>
</head>
<body>
<form id="myForm" action="">
<p><input type="text" id="myTextBox1"/> <span id="myTextBox1_erreur"></span></p>
<p><input type="text" id="myTextBox2"/> <span id="myTextBox2_erreur"></span></p>
<p><input type="text" id="myTextBox3"/> <span id="myTextBox3_erreur"></span></p>
<p>
<input type="button" value="Appliquer" id="validation" onclick="lance_verif();" />
</p>
<form>
</body>
</html> |