/    Sign up×
Community /Pin to ProfileBookmark

onblur and focus issues

Hello,

I’m trying to use onblur to validate a textfield. I want to use on blur because there is the possibility that the user will use either a mouse or the tab button to navigate the form.

The code I did was something like:
function checkNull(formField){
var value = formField.value;

if(value==null || value==””){
alert(“This is a mandatory field. Please enter something”);
formField.focus();
}

}

I’ve read that when an alert (window.alert() dialog box) is displayed, the textfield loses focus and then regains focus after the alert is closed. This can cause a loop to form. In my case if I leave out the formField.focus() line, the cursor returns to whatever other textfield you had tabbed onto. But if put in the formField.focus() line the code seems to go into a loop. Every time you click on the OK button in the alert box another alert box pops up.

Is there any way to prevent this loop from happening ?

Thanks in adavance,

Trish.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@KorApr 05.2006 — Wouldn't be easier to validate onsubmit?
×

Success!

Help @trishah spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...