Javascript form validation - multiple form fields larger than 0
- by calebface
function negativeValues(){
var myTextField = document.getElementById('digit');
if(myTextField.value < 0)
{
alert("Unable to submit as one field has a negative value");
return false;
}
}
Above is a Javascript piece of code where every time a field id 'digit' has a value that's less than 0, than an alert box appears either onsubmit or onclick in the submit button.
There are about 50 fields in the form that should be considered 'digit' fields where they shouldn't be anything less than 0. What should I change with this Javascript to ensure that all 'digit' like fields have this alert box pop up?
I cannot use jquery/mootools for validation - it has to be flat Javascript.
Thanks.