Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onBlur & Validation

Status
Not open for further replies.

toddOne

Programmer
Jul 20, 2001
41
0
0
US
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.

any suggestions would be great!

onchange doesn't provide me with the functionality i desire.
 
All I can say that you need some change in the logic of validation process.
It's impossible to tell anything particular unless you post your code - there are no universal solutions.

good luck
 
ok.....here is my code

<script language=&quot;JavaScript&quot; type = &quot;text/javascript&quot;>
var whitespace = &quot; \t\n\r&quot;;
function fieldValidate(fld, typ, desc)
{
var checkToMake = typ;
var field = fld;
var d = desc;

switch (checkToMake)
{
case 'notblank': if (isEmpty(field.value))
{
alert(d + &quot; may not be empty&quot;);
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 >= &quot;0&quot;) && (c <= &quot;9&quot;) || (c == &quot;.&quot;))
}
function isInteger(field, desc)
{
var i, c;
var s = field.value;
var d = desc

if (isEmpty(s))
{
alert(d + &quot; cannot be empty&quot;);
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 + &quot; must contain only digits&quot;);
field.focus();
return false;
}
}
return true;
}
</script>

example call of fieldValidate:
Login: <input type=&quot;text&quot; name=&quot;txtBox&quot; id=&quot;txtBox&quot; size=&quot;30&quot; onblur=&quot;fieldValidate(txtBox, 'isnumber', 'Login')&quot;><br>

now if the following field was defined with the same use of onblur i get stuck in an endless loop of alert boxes....
....thanks in advance for any suggestions!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top