473,387 Members | 1,578 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,387 software developers and data experts.

ONBLUR() LOOP

I do validate my form using onblur() event.

In my example I have 3 fields in my form.
name,address and city. I call my functions using onblur()="isname(this)"
...etc. My probllem is that when I fill the form fields everything is
fine. When I dont I have a problem. When I leave empty field for lets say
name the the isname() function is called and tells my to enter the data.
It tries to focus on that field and select it. The problem is that when I
change the focus from name to the second field address the second script
is already running. So when I click OK on my alert message I cant fill in
the field because second field validation function runs. So I am in the
loop. WHY? Is there any way I can stop the computer to focus on next
field when I press tab or click on the next field. Whats wrong.
Thats my code.

function isname(field) {
if (field.value == "") {
alert("Value is required");
field.focus();

field.select();
}
else {
if (field.value.split(" ").length < 2) {
alert("Enter a full name");
field.focus();

field.select();
}
}
}

function isaddress(field) {
if (field.value == "") {
alert("Value is required");
field.focus();
field.select();
}
}

function iscity(field) {
if (field.value == "") {
alert("Value is required");
field.focus();
field.select();
}
}
Thanks a lot

Jul 20 '05 #1
1 4234
Bartosz Wegrzyn wrote:
I do validate my form using onblur() event.

In my example I have 3 fields in my form.
name,address and city. I call my functions using onblur()="isname(this)"
..etc. My probllem is that when I fill the form fields everything is
fine. When I dont I have a problem. When I leave empty field for lets say
name the the isname() function is called and tells my to enter the data.
It tries to focus on that field and select it. The problem is that when I
change the focus from name to the second field address the second script
is already running. So when I click OK on my alert message I cant fill in
the field because second field validation function runs. So I am in the
loop. WHY? Is there any way I can stop the computer to focus on next
field when I press tab or click on the next field. Whats wrong.
Thats my code.

function isname(field) {

if (field.value == "") {

alert("Value is required");

field.focus();

field.select();

}

else {

if (field.value.split(" ").length < 2) {

alert("Enter a full name");

field.focus();

field.select();

}

}

}

function isaddress(field) {

if (field.value == "") {

alert("Value is required");

field.focus();

field.select();

}

}

function iscity(field) {

if (field.value == "") {

alert("Value is required");

field.focus();

field.select();

}

}
Thanks a lot

Onblur() has lots of problems as you noted. It is not really suitable
for that purpose.

Try using onchange instead.

Jul 20 '05 #2

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

Similar topics

2
by: Bartosz Wegrzyn | last post by:
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...
1
by: Tzachi | last post by:
Hello all, I have a function that dynamically adds rows and columns to the page. Everything works well except onfocus // onblur attributes. For some reason, when entering the input box it...
1
by: Christoph | last post by:
I'm trying to validate some HTML form elements when the user tabs out of each element. However, I'm having some problems. It appears that the order of events is onChange followed some time...
3
by: Robert Oschler | last post by:
I have a textarea element that I have created an onblur() handler for. In the onblur() handler, I check to make sure that they have saved the contents of the edit box, before leaving it. If...
1
by: neil S via DotNetMonster.com | last post by:
I have a custom control with a textbox and dropdown list. The dropdown list is hidden and acts as a data source for the textbox. When the user enters text in the textbox, an onKeyup event is...
4
by: botski007 | last post by:
We have a loop that calculates argValue = someIntegerValue; component.onblur = function() { callFun( this, argValue ) }; loop The problem is that the onblur call is exactly "callFun( this,...
1
by: Duncan | last post by:
Hi all, I'm tearing my hair out on this! I have a simple ASP.NET 2 page with a TextBox control, in the PreRender I set ClientSide events:- Response.Attributes.Add("onchange",...
4
by: rubenhan | last post by:
Hey, guys. My basic idea is this. When I write "1" in the pre-existing text field and onblur, I want to add a new field with a set of attributes, which turned out to be the same as the pre...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...

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.