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

Problem Validating One Input Before Going On To Another.

P: n/a
I have a form with multiple input boxes. I want to validate each input
box (and force user to correct it) before allowing user to move to
another, either using tab key or a mouse click.

I try onchange/on blur to activate a javascript function to check the
input for correctness once user moves out of the input box (tab or mouse
click). If it looks OK, then nothing happens. But if an error is
detected, the function puts out an alert box and then use focus() and
select() methods to bring the focus back to the error'ed input box.

The result of the coding is that the error'ed input was selcted, but the
cursor still goes to the NEXT input box. It looks like the focus()
method did not last.

I suspect that the mouse click event still takes place after focusing on
the error'ed input box.

My question then is: Is there a way to stop that, and keep the focus on
the error'ed box? I really do not like to validate all the input boxes
AFTER the user enters all the inputs.

Thanks for the help.
Jun 23 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Jun 23, 2:32 pm, Louis <t051...@hotmail.comwrote:
I have a form with multiple input boxes. I want to validate each input
box (and force user to correct it) before allowing user to move to
another, either using tab key or a mouse click.

I try onchange/on blur to activate a javascript function to check the
input for correctness once user moves out of the input box (tab or mouse
click). If it looks OK, then nothing happens. But if an error is
detected, the function puts out an alert box and then use focus() and
select() methods to bring the focus back to the error'ed input box.

The result of the coding is that the error'ed input was selcted, but the
cursor still goes to the NEXT input box. It looks like the focus()
method did not last.

I suspect that the mouse click event still takes place after focusing on
the error'ed input box.

My question then is: Is there a way to stop that, and keep the focus on
the error'ed box? I really do not like to validate all the input boxes
AFTER the user enters all the inputs.
Hard to say without having the code or a URL to look at.
In any case, I'd say bite the bullet and validate after,
nothing annoys people more than being told what to do,
especially with f'n dialog boxes that pop up and insist
on being paid attention to.

*PING* "Hi, look at me, you screwed up, moron, fix it
now or else. But before I'll allow you the privilege
of fixing your asinine infantile error, you've got to
click my button or I won't go away."

On a personal note, I've gone to sites to place orders,
for a fair bit of dosh, only to walk away and spend the
money somewhere else because the person programming the
interface couldn't be bothered to make it more friendly.

---
Geoff

Jun 23 '07 #2

P: n/a
ASM
Louis a écrit :
I have a form with multiple input boxes. I want to validate each input
box (and force user to correct it) before allowing user to move to
another, either using tab key or a mouse click.
it is not a good way to do

prefer to validate these fields on submit

function validate(what) {
var F = what.elements;
for(var i=0; i<F.length; i++) {
if(F[i].type=='text' && F[i].value.length<=0) {
alert('please complete field : '+F[i].name);
F[i].focus();
F[i].select()
return false;
}
}
return true;
}
<form onsubmit="return validate(this);" blah >

--
Stephane Moriaux et son (moins) vieux Mac
Stephane Moriaux and his (less) old Mac already out of date
Jun 23 '07 #3

P: n/a
rf

"Louis" <t0*****@hotmail.comwrote in message
news:KGdfi.8893$tB5.828@edtnps90...
>I have a form with multiple input boxes. I want to validate each input box
(and force user to correct it) before allowing user to move to another,
either using tab key or a mouse click.
What a horrible sounding form.

--
Richard.
Jun 24 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.