473,544 Members | 1,149 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Onblur() event cause infinite loop

I use onblue event to validate fields in my form.
I do this onblur="return isname()" and so so ...

I have one form with 20 fields.

My problem is that when the focus is for example on the first field of my
form
the "name" field and I click somewher or press tab than I loose focus and my
isname() function is executed. Everything is fine but the focus was change
for next field
lets say "address" and the next function is executed isaddress(). Although
my isname() function tries to change the focus back to name field the other
function is executed.
This cause infinite loop and I cannot access the form anymore.

I know I can use the onchange() event handler but for me it will not work.
I need onblur(). Is this code wrong. Maybe the way I code is bad. Please
help.

THE CODE:
function iscustomerid() {

var string1 = document.form1. customerid.valu e;

if (string1 == "") {

}
return true;
}
function isname() {

var string2 = document.form1. name.value;

if (string2 == "" ) {
alert("Value is required");
document.form1. name.focus();
document.form1. name.select();
return false;
}
else {
if (string2.split( " ").length < 2) {
alert("Enter a full name");
document.form1. name.focus();

document.form1. name.select();
return false;
}
}
return true;
}
function isaddress() {

var string3 = document.form1. address.value;
if (string3 == "" ) {
alert("Value is required");
document.form1. address.focus() ;
document.form1. address.select( );
return false;
}

return true;
}

function iscity() {

var string4 = document.form1. city.value;

if (string4 == "") {
alert("Value is required");
document.form1. city.focus();
document.form1. city.select();
return false;

}

return true;
}

function isstate() {

var string5 = document.form1. state.value;

if (string5 == "") {

}
return true;
}

function iszipcode() {

var string6 = document.form1. zipcode.value;
if (string6 == "") {
alert("Value is required");
document.form1. zipcode.focus() ;
document.form1. zipcode.select( );
return false;
}
return true;
}

function isemail() {

var string7 = document.form1. email.value;

if (string7 == "") {

}
return true;
}

function isphone() {

var string8 = document.form1. phone.value;

if (string8 == "") {
alert("Value is required");
document.form1. phone.focus();
document.form1. phone.select();
return false; }
return true;
}

function isss() {

var string9 = document.form1. ss.value;

if (string9 == "") {

}
return true;
}

function iscc() {

var string10 = document.form1. cc.value;

if (string10 == "") {

}
return true;
}

function isexp() {

var string11 = document.form1. exp.value;

if (string11 == "") {

}
return true;
}

function isdate() {

var string12 = document.form1. date.value;

if (string12 == "") {
alert("Value is required");
document.form1. date.focus();
document.form1. date.select();
return false;
}
return true;
}

function istime() {

var string13 = document.form1. time.value;

if (string13 == "") {

}
return true;
}

function isservice() {

var string14 = document.form1. service.value;

if (string14 == "") {
alert("Value is required");
document.form1. service.focus() ;
document.form1. service.select( );
return false;
}
return true;
}

function isdue() {

var string15 = document.form1. due.value;

if (string15 == "") {
alert("Value is required");
document.form1. due.focus();
document.form1. due.select();
return false;
}

return true;

}

function isextrawork() {

var string16 = document.form1. extrawork.value ;

if (string16 == "") {

}
return true;
}

function isdue2() {

var string17 = document.form1. due2.value;

if (string17.value == "") {

}
return true;
}

function isspecial() {

var string18 = document.form1. special.value;

if (string18 == "") {

}
return true;
}
function iscompany() {

var string19 = document.form1. company.value;

if (string19 == "") {
}
return true;
}
function isinstaller() {

var string20 = document.form1. installer.value ;
if (string20 == "") {
}
return true;
}
function check() {

alert('Thank You. Now print the work order');
return true;
}Thats how my validate script looks like:
Jul 20 '05 #1
2 12983

"Bartosz Wegrzyn" <bl*******@lexo n.ws> schreef in bericht
news:uF******** *************@n ewssrv26.news.p rodigy.com...
I use onblue event to validate fields in my form.
I do this onblur="return isname()" and so so ...

I have one form with 20 fields.

My problem is that when the focus is for example on the first field of my
form
the "name" field and I click somewher or press tab than I loose focus and my isname() function is executed. Everything is fine but the focus was change
for next field
lets say "address" and the next function is executed isaddress(). Although my isname() function tries to change the focus back to name field the other function is executed.
This cause infinite loop and I cannot access the form anymore.

I know I can use the onchange() event handler but for me it will not work.
I need onblur(). Is this code wrong. Maybe the way I code is bad. Please
help.

THE CODE:

<code snipped>


Hi,

If you insist in using onblur you will have to follow a somewhat different
approach. As you have noticed, setting focus to a field that did not
validate triggers an onblur for a field that should not be validated yet.
You will have to suppress the validation for the second field.
One way of solving this is using only one function for validating, passing
the name of the field to be validated, and do validations for that field
only until there is no need to reset focus.

var nowValidatingFi eld='';
function val(nameOfField ){
// return directly if validating another field
if (nowValidatingF ield!=''&&nowVa lidatingField!= nameOfField) return;
// set global var to suppress other validations
nowValidatingFi eld=nameOfField ;
// do validations for each field
if (nameOfField==' field1'){
if (!OK){
alert ('this is wrong')
document.form1. field1.focus();
document.form1. field1.select() ;
return false
}
}
//etc..
// so all is ok! reset global var to release function for new field.
nowValidatingFi eld='';
return true
}

Fred
Jul 20 '05 #2
thanks I will try it
"Fred Serry" <ge*******@hotm ail.com> wrote in message
news:bj******** ****@ID-108377.news.uni-berlin.de...

"Bartosz Wegrzyn" <bl*******@lexo n.ws> schreef in bericht
news:uF******** *************@n ewssrv26.news.p rodigy.com...
I use onblue event to validate fields in my form.
I do this onblur="return isname()" and so so ...

I have one form with 20 fields.

My problem is that when the focus is for example on the first field of my form
the "name" field and I click somewher or press tab than I loose focus and
my
isname() function is executed. Everything is fine but the focus was

change for next field
lets say "address" and the next function is executed isaddress().

Although
my isname() function tries to change the focus back to name field the

other
function is executed.
This cause infinite loop and I cannot access the form anymore.

I know I can use the onchange() event handler but for me it will not work. I need onblur(). Is this code wrong. Maybe the way I code is bad. Please help.

THE CODE:

<code snipped>


Hi,

If you insist in using onblur you will have to follow a somewhat different
approach. As you have noticed, setting focus to a field that did not
validate triggers an onblur for a field that should not be validated yet.
You will have to suppress the validation for the second field.
One way of solving this is using only one function for validating, passing
the name of the field to be validated, and do validations for that field
only until there is no need to reset focus.

var nowValidatingFi eld='';
function val(nameOfField ){
// return directly if validating another field
if (nowValidatingF ield!=''&&nowVa lidatingField!= nameOfField) return;
// set global var to suppress other validations
nowValidatingFi eld=nameOfField ;
// do validations for each field
if (nameOfField==' field1'){
if (!OK){
alert ('this is wrong')
document.form1. field1.focus();
document.form1. field1.select() ;
return false
}
}
//etc..
// so all is ok! reset global var to release function for new field.
nowValidatingFi eld='';
return true
}

Fred

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
5530
by: Gremlin | last post by:
If you are not familiar with the halting problem, I will not go into it in detail but it states that it is impossible to write a program that can tell if a loop is infinite or not. This is a fallacy built on the assumption of mythical infinite all powerfull machines. In reality we deal with finite machines that are capable of two states in...
2
3701
by: D. Alvarado | last post by:
Hi, I'm having some trouble with the "onBlur" event in the BODY tag. Ideally, what I want to happen is that when someone leaves window A, window A executes a command. I had put <body onBlur="savePage();"> I have a couple of problems. On IE 6 (win2000), whenever I put the cursor focus on a textfield within window A, the "savePage"...
5
7570
by: Dave Hammond | last post by:
Hi All, I have a web form which performs certain actions upon moving focus away from a field. However, if the user clicks the top corner 'X' icon to close the window, the onBlur event still fires. If, for example, the onBlur event was an alert() popup: when the user clicks the close window icon, the window closes and then the alert pops...
1
5197
by: Jim P. | last post by:
I'm having trouble returning an object from an AsyncCallback called inside a threaded infinite loop. I'm working on a Peer2Peer app that uses an AsyncCallback to rerieve the data from the remote peer. I have no problem connecting the peers and streaming Network Streams. When the incoming data is finished recieving, I act upon it. This...
11
6003
by: Alexander Bosch | last post by:
Hi, I'm having a problem similar to the one that's stated in this KB http://support.microsoft.com/default.aspx?scid=kb;en-us;839521 When I'm posting a page to itself with the bool value as true it falls into an infinite loop and later a StackOverflow Exception. I need to do this and not a Response.Redirect or a transfer with the bool in...
2
4200
by: scottys0 | last post by:
Hi everyboy, I'm working in an IOC-IBM (IBM open class) replamecent library. the code seens confused but , no, isn't. #define INumber long class IString : public std::string { private: ... // some control variables
1
2534
by: Bob | last post by:
The below regular express can sometimes cause an infinite loop. Anyone know what could cause this? string RegexSig = @"To:*\s*(?<address>\S+@\S+)*(\s|\S)*did not reach the following recipient"; Also shouldn't the framework have some type of loop protection? This will run forever. Bob
10
7627
by: Steven Woody | last post by:
i have a program which always run dead after one or two days, i think somewhere a piece of the code is suspicious of involving into a infinite loop. but for some reason, it is very hard to debug. so i thing there might be tool which can statically analysis the code and notice me this kind of potential problems if found. any suggestion? ( i...
44
4320
by: James Watt | last post by:
can anyone tell me how to do an infinite loop in C/C++, please ? this is not a homework question .
0
7429
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7368
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7614
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7777
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7384
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5301
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4922
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3420
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
990
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.