Ok, your description is a bit vague but here is one solution.
If your html looks like this
<!DOCTYPE html>
<html>
<head>
<title>Form</title>
</head>
<body>
<form id = "important_form">
<input type = "text" value = "0"/>
<input type = "text" value = "0"/>
<input type = "text" value = "0"/>
<input type = "submit" value = "submit"/>
</form>
<script type = "text/javascript" src="validate.js"></script>
</body>
</html>
Then you could use javascript similar to this
form = document.getElementByID("important_form");
//This will execute when the user presses the submit button.
form.onsubmit = function() {
//Loop through all form elements.
for(var i = 0; i < form.elements.length; i++) {
//If the form element is a text input and the value is not an integer
if(form.elements[i].type == "text" &&
parseInt(form.elements[i].value) != form.elements[i].value) {
alert("Please enter an integer value"); //Replace this with whatever you want
//to do with invalid results
return false; //Stops the submit from continuing.
}
}
return true;
}
{}
button to format your code in the future. I took care of it, but did not fix any syntax. – Dutchie432 Apr 4 '11 at 11:46{}
(in text-editor) to format code. Your html tags will also be printed – experimentX Apr 4 '11 at 12:08