Javascript form validation - multiple form fields larger than 0
Posted
by
calebface
on Stack Overflow
See other posts from Stack Overflow
or by calebface
Published on 2011-02-21T07:22:18Z
Indexed on
2011/02/21
7:25 UTC
Read the original article
Hit count: 243
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.
© Stack Overflow or respective owner