1 <html> 2 <head> 3 <script> 4 var OK2Submit = false; 5 function validateMove() 6 { 7 OK2Submit = false; 8 document.getElementById("moveDiv").innerHTML="<i>Validating move...</i>"; 9 var xmlhttp; 10 if (window.XMLHttpRequest) 11 {// code for IE7+, Firefox, Chrome, Opera, Safari 12 xmlhttp=new XMLHttpRequest(); 13 } 14 else 15 {// code for IE6, IE5 16 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 17 } 18 xmlhttp.onreadystatechange=function() 19 { 20 if (xmlhttp.readyState==4 && xmlhttp.status==200) 21 { 22 var moveGood=xmlhttp.responseText; 23 if(moveGood.charAt(0)=="t"){ 24 OK2Submit=true; 25 document.getElementById("moveDiv").innerHTML='<i>That is a valid move, you may submit it</i><br><input type="submit" value="Submit">'; 26 } 27 else { 28 document.getElementById("moveDiv").innerHTML="<i>Not a valid move!</i>"; 29 } 30 } 31 } 32 xmlhttp.open("GET","validate_move.py?"+document.forms["myForm"]["move"].value,true); 33 xmlhttp.send(); 34 return false; 35 } 36 </script> 37 </head> 38 39 <body> 40 <form name="myForm" action="action.py" onsubmit="return OK2Submit" method="post"> 41 Enter Move: <input type="text" name="move" onchange="validateMove();"> 42 <br> 43 <div id="moveDiv"></div> 44 <br> 45 </form> 46 </body> 47 </html>