By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,688 Members | 1,738 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,688 IT Pros & Developers. It's quick & easy.

ONBLUR() LOOP

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.