Bonjour,

Ma fonction javascript ne fonctionne pas et je sais pas pourquoi.

Code de la page :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE html>
<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=iso-88859-1"/>
   <title>Jeu</title>
   <link rel="stylesheet" href="CSS/feuille.css" />
   <link rel="shortcut icon" type="image/x-icon" href="Images/icone.ico" />
   <img src="Images/proba.png" style="display:block;margin:auto;width:256px:height:256px;vertical-align:middle" />
   <script type="text/javascript" src="Javascript/Verification.js"></script>
   <script type="text/javascript" src="Javascript/Jquery.js"></script>
 
</head>
 
<body>
 
<?php
// on vérifie si le nombre a déjà été généré
// dans ce cas il sera renvoyé par le formulaire de saisie
if (isset($_POST['mystere']) && ctype_digit($_POST['mystere'])) {
   $nombre = $_POST['mystere'];
}
else {
   $nombre = mt_rand(1, 100);
   //echo $nombre;
}
 
// on récupère le nombre de tentatives déjà faites
if (isset($_POST['nbTentatives']) && ctype_digit($_POST['nbTentatives'])) {
   $nbTentatives = $_POST['nbTentatives'];
   // on incrémente
   $nbTentatives += 1;
}
else {
   $nbTentatives = 0;
}
 
$essaisRestants = 7 - $nbTentatives;
?>
 
   <form method="post" action="jeu.php" name="formJeu">
      <fieldset style=" width:500px; height:220px">
         <p align="center">Entrer un nombre entre 0 et 100 :
            <input type="text" name="choixnombre" id="choixnombre" value="" size="7" required="required"/>
            <input type="hidden" name="mystere" value="<?php echo $nombre; ?>" />
            <input type="hidden" name="nbTentatives" value="<?php echo $nbTentatives; ?>" />
            </br>
			</br>
            <input type="button" value="Vérifier" id="Vérifier" onclick="verification()" style="font-size:100%">
         </p>
         Essais restant : <?php echo $essaisRestants; ?>
		 </br>
		 </br>
 
   </form>
   <?php
   //on récupère le nombre saisie par l'utilisateur pour le comparer au nombre généré aléatoirement
 	if (isset($_POST['choixnombre'])) { 
	$choixnombre = $_POST['choixnombre'];
	?>
   <?php if($essaisRestants > 0): ?>
	<?php if ($nombre > $choixnombre): ?>
		<div align="center">Le nombre choisi est trop petit !</div>
	<?php else: ?>
		<?php if ($nombre < $choixnombre): ?>
			<div align="center">Le nombre choisi est trop grand !</div>
		<?php else: ?>
 
		<script>$('#Vérifier').replaceWith('<a href="Accueil.php">Retour</a>');</script>
		<script>$('#choixnombre').replaceWith('<input type="text" name="choixnombre" id="choixnombre" value=""  size="9" disabled />');</script>
 
			<div align="center">Bravo, vous avez trouvé le nombre mystère !</div>
		<?php endif; ?>
	<?php endif; ?>
	<?php endif; ?>	
	<?php if($essaisRestants == 0): ?>
			<div align="center">Vous avez perdu !</div>	
			<div align="center">le nombre mystère était : <?php echo $nombre ?></div>
		<script>$('#Vérifier').replaceWith('<a href="Accueil.php">Retour</a>');</script>
		<script>$('#choixnombre').replaceWith('<input type="text" name="choixnombre" id="choixnombre" value=""  size="9" disabled />');</script>
	<?php endif; ?>
	<?php } ?> 
	</fieldset>
</body>
</html>
Et le code de ma fonction

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function verification() {
      var nb = document.getElementById("choixnombre").value;
      if (isNaN(nb)) {
         alert("Rentrez un nombre");
         document.getElementById("choixnombre").value="";
      }
      else
      if ((nb > 100) || (nb < 0)) {
         alert("Rentrez un nombre entre 0 et 100");
         document.getElementById("choixnombre").value = "";
      }
      else {
         document.formJeu.submit();
      }
   }