473,324 Members | 2,268 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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.value;

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 12934

"Bartosz Wegrzyn" <bl*******@lexon.ws> schreef in bericht
news:uF*********************@newssrv26.news.prodig y.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 nowValidatingField='';
function val(nameOfField){
// return directly if validating another field
if (nowValidatingField!=''&&nowValidatingField!=nameO fField) return;
// set global var to suppress other validations
nowValidatingField=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.
nowValidatingField='';
return true
}

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

"Bartosz Wegrzyn" <bl*******@lexon.ws> schreef in bericht
news:uF*********************@newssrv26.news.prodig y.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 nowValidatingField='';
function val(nameOfField){
// return directly if validating another field
if (nowValidatingField!=''&&nowValidatingField!=nameO fField) return;
// set global var to suppress other validations
nowValidatingField=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.
nowValidatingField='';
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
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...
2
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...
5
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...
1
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...
11
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...
2
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:...
1
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"; ...
10
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....
44
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
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.