This week's book giveaway is in the Testing forum.
We're giving away four copies of Practical Unit Testing with TestNG and Mockito and have Tomek Kaczanowski on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes onblur errors in Netscape Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Practical Unit Testing with TestNG and Mockito this week in the Testing forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "onblur errors in Netscape" Watch "onblur errors in Netscape" New topic
Author

onblur errors in Netscape

kat luna
Greenhorn

Joined: Jul 20, 2001
Posts: 16
Hi all.
We are doing form validation using the onBlur event to make sure each textbox is filled before moving on to the next one. However this produces an endless loop in Netscape and you have to close the browser to escape (not very user friendly ).
I have searched the archives here and several people recommended the onBlur event for validation. Has anyone found a way around the Netscape problem or do you all code for IE only?
Here is my code:
<SCRIPT LANGUAGE="JavaScript">
<!--
function verify(field) {
var str = field.name;
if(field.value == "") {
alert("The field is " + str);
field.focus();
}
}
//-->
</SCRIPT>
....
<FORM>
SSN:<input type="text" name="ssn" onBlur="verify(this)" maxlength="9">
First Name: <input type="text" name="firstName" onBlur="verify(this)">
Last Name:<input type="text" name="lastName" onBlur="verify(this)">
</FORM>
Gazza Bee
Greenhorn

Joined: Feb 17, 2003
Posts: 2
I'm getting the same thing thing in IE6! About to chuck my box out the window.
Here's my javascript:
function checkForNull(elm,elmVal){
if(elmVal==""){
alert("Please enter a value.");
elm.focus();
return false;
}
}
and in the form:
<input ..... onBlur="checkForNull(this,this.value);">
Seems innocent enough, but loops endlessly. I'm dyin' here. Can anyone help with this pleeeease?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15003
the reason why is that it will always be blurred, you need to refocus it. See if this works.
Also look in my sig. below:
onblur="ValidateIt(this)"
function ValidateIt(X){
if(X.value=""){
alert('Error ;
X.focus();
}
else return true;
}
 
 
subject: onblur errors in Netscape
 
Threads others viewed
Help required
Cross browser issues
onblur/onchange workaround needed...
How can i trace this..
JSP and Javascript problem
MyEclipse, The Clear Choice