@steelersfan88Mar 25.2004 — #I am going to post an article about this, but here you go:[code=php]<script type="text/javascript">
var times = 0
function checkVals() { var theField = new Array; var theName = new Array var numFields = 2 //five text boxes to validate for(var i=0;i<numFields;i++) { // id your fields as myText0, myText1, etc. theField[i] = document.getElementById('myText'+ i).value theName[i] = 'myText'+ i } var errors = "" var confirm = "" for(var k=0;k<theField.length;k++) { if(!/^[0-9]+$/.test(theField[k])) { errors += "The Text Field, "+ theName[k] +", is invalid.<BR><BR>" } confirm += theName[k] +": <B>"+ theField[k] +"</b><BR>" } if(errors.length > 1) { var newWin = window.open('','_blank',config="toolbars=no,status=nu,menubars=no,directories=no,scrollbars=yes,height=280,width=300") newWin.document.write("<center><h1>Errors:</h1>") newWin.document.write(errors) newWin.document.close() return false; } else if(times == 0) { var newWin2 = window.open('','_blank',config="toolbars=no,status=nu,menubars=no,directories=no,scrollbars=yes,height=300,width=170") newWin2.document.write("<center><h1>Confirm<BR>Input:</h1></center>") newWin2.document.write(confirm) times = 1 return false; } else { return true; } }
function resetTimes() { times = 0 }
</script>
<form name="myForm" onSubmit="return checkVals()" action=""> Enter numbers: <input type="text" name="myText0" id="myText0" onchange="resetTimes()"><BR> Enter numbers: <input type="text" name="myText1" id="myText1" onchange="resetTimes()"><BR> <input type="submit" value="Validate Numbers!"> </form>[/code]Note, that this form must be changed, and I have made a short validator that makes sure fields are filled in. It can be configured if you reply!
NOTE: The script will continue to confirm entries until you do NOT make a change in them. Then it will submit.