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
|
<!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" lang="fr">
<head>
<title>Test de formulaire pour l'expérience</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<?php echo $_POST['case']; ?>
<form method="post" action="index.php">
<input id="case1" type="text" name="case1" />
<input id="submit" type="submit" value="Valider" onClick="soumettre()" />
</form>
<script type="text/javascript">
var e1 = document.getElementById('case1');
var tps_case = 0;
var tps_temp = 0;
//fonction pour calculer les écarts de temps
function timestamp() {return Math.round((new Date()).getTime()/1000);}
function soumettre() {
$.post("index.php", { case: tps_case} );
return true; // Doit retourner vrai, sinon le click sur le bouton est annulé
}
// Récupération d'informations lorsque l'utilisateur utilise la case 'case1'
e1.addEventListener('focus',function(e){tps_temp = timestamp() ; },false);
// Lorsque que l'utilisateur 'sort' de la case, je récupère la variable.
e1.addEventListener('blur',function(e){tps_case = timestamp() - tps_temp ; },false);
</script>
</body>
</html> |