i have multiple <input />
text boxes in my HTML document’s form, when the user clicks the submit button i need to go through those Text boxes and validate them all, that they have only numeric values, if anyone fails the validation, the submit will be aborted, i don’t want to use named input boxes instead i prefer using more dynamic solution and access the input boxes without naming them.
this is my html code:
<html>
<head>
<title>My Project 1.0.1</title>
<script type='javascript'>
function validateBoxes(inputbox)
{
var regex = /^[-+]?[0-9]+$/;
if (inputbox.value.match(regex))
return true;
else {
alert("Invalid value ["+inputbox.value+"], input numeric value only.");
inputbox.focus();
return false;
}
}
</script>
</head>
<body>
<form method="post" action="/validation_success.php">
ID 1: <input type='text' id='input_numeric'/>
ID 2: <input type='text' id='input_numeric'/>
ID 3: <input type='text' id='input_numeric'/>
ID 4: <input type='text' id='input_numeric'/>
<input type='submit' onclick="validateBoxes(document.getElementById('input_numeric'))"
value='Submit'/>
</form>
</body>
</html>