I am currently doing validation checks for most every text box in my form, but b/c part of the check is whether or not the field is empty i am having a problem with onblur. if a textbox is blank and the user tabs to the next textbox i receive the desired result (alert box), but b/c the there is a validation check on the field that was next in the tab order i now receive an additional, undesired alert box b/c that field is blank....creating an endless loop of alert boxes.
any suggestions would be great!
<script language="JavaScript" type = "text/javascript">
var whitespace = " \t\n\r";
function fieldValidate(fld, typ, desc)
{
var checkToMake = typ;
var field = fld;
var d = desc;
switch (checkToMake)
{
case 'notblank': if (isEmpty(field.value))
{
alert(d + " may not be empty"
;
field.focus();
}
break;
case 'isnumber': if(!isInteger(field, desc))
break;
}
}
function isEmpty(s)
{
var i;
if ((s==null) || (s.length ==0))
return true;
// Search string looking for characters that are not whitespace
for (i=0; i < s.length; i++)
{
var c = s.charAt(i);
if (whitespace.indexOf(c) == -1)
return false;
}
// All characters are whitespace.
return true;
}
function isDigit(c)
{
return ((c >= "0"
&& (c <= "9"
|| (c == "."
)
}
function isInteger(field, desc)
{
var i, c;
var s = field.value;
var d = desc
if (isEmpty(s))
{
alert(d + " cannot be empty"
;
field.focus();
return false;
}
for (i=0; i<s.length; i++)
{
//Check if all caharacters are numbers
c = s.charAt(i);
if (!isDigit(c))
{
alert(d + " must contain only digits"
;
field.focus();
return false;
}
}
return true;
}
</script>
example call of fieldValidate:
Login: <input type="text" name="txtBox" id="txtBox" size="30" onblur="fieldValidate(txtBox, 'isnumber', 'Login')">
....thanks in advance for any suggestions!
any suggestions would be great!
<script language="JavaScript" type = "text/javascript">
var whitespace = " \t\n\r";
function fieldValidate(fld, typ, desc)
{
var checkToMake = typ;
var field = fld;
var d = desc;
switch (checkToMake)
{
case 'notblank': if (isEmpty(field.value))
{
alert(d + " may not be empty"
field.focus();
}
break;
case 'isnumber': if(!isInteger(field, desc))
break;
}
}
function isEmpty(s)
{
var i;
if ((s==null) || (s.length ==0))
return true;
// Search string looking for characters that are not whitespace
for (i=0; i < s.length; i++)
{
var c = s.charAt(i);
if (whitespace.indexOf(c) == -1)
return false;
}
// All characters are whitespace.
return true;
}
function isDigit(c)
{
return ((c >= "0"
}
function isInteger(field, desc)
{
var i, c;
var s = field.value;
var d = desc
if (isEmpty(s))
{
alert(d + " cannot be empty"
field.focus();
return false;
}
for (i=0; i<s.length; i++)
{
//Check if all caharacters are numbers
c = s.charAt(i);
if (!isDigit(c))
{
alert(d + " must contain only digits"
field.focus();
return false;
}
}
return true;
}
</script>
example call of fieldValidate:
Login: <input type="text" name="txtBox" id="txtBox" size="30" onblur="fieldValidate(txtBox, 'isnumber', 'Login')">
....thanks in advance for any suggestions!