Re: focus after onchange event and regex test not working
- From: RobG <rgqld@xxxxxxxxxxxx>
- Date: Tue, 28 Feb 2006 02:32:42 GMT
jab3 wrote:
Hello. I"m new to this group, and to JavaScript in general, so please
forgive me if I breach local etiquette. I'm trying to implement some
client-side 'dynamic' validation on a form. I'm having a couple of
problems, which I'll try to describe. But this e-mail will only
reproduce one of them, in a "short" example. What I'm generally doing
is having each form entry contained in a div, which as a label, an
input with some event handlers, and a span that provides contextual
help. Example:
<div class="form_entry">
<label>Username:</label>
<input name="uname" id="uname" type="text" onfocus="focus_event"
onblur="blur_event"
onchange="verify_new_username()" />
<span id="uname_help"></span>
</div>
The focus_event and blur_event functions are taken out for brevity.
That may be addressed in another email; they just hide and un-hide
default text in the span.
The specific problem I'm asking about here involves focusing and
altering innerHTML after a regex check, apparently with an onchange
handler. The code example will follow at the end of the message. But
what I would like to happen is, the person enters and e-mail address.
After entering the first e-mail address, the onchange event handler
calls a function that runs a basic regex against the email to see if it
fits some basic parameters. If the test fails, I would like to change
the span for that entry, then keep focus there until the e-mail
validates.
No, don't. Do not trap the user in a field until they 'get it right', that kind of behaviour drives users bezerk.
It might be that your regular expression is not appropriate for their e-mail address, or they may have partially completed the field and gone off do to something else (like check what their e-mail address is). Further, the fact that the e-mail address fits your regular expression does not make it valid. And if the user turns off scripting you can't validate anything at the client, they can enter whatever they like.
By all means provide a helpful message onchange if you think the address is wrong, but that's it.
You should deal with it at the server - send a confirmation e-mail to the supplied address. If it bounces or they don't respond within say 48 hrs, scratch them.
The problem is that the focus won't stay there.
I wouldn't call that a problem, I'd say it's a bonus. :-)
Here are some things I've figured out with tinkering. If I change the
event handler to onblur instead of onchange, it works with IE, but not
Firefox. But it needs to be onchange because onblur is already being
used to hide the <span /> help text when the user moves focus. Also,
You can call more than one function from the same event.
<input onblur="func01(); func02(); ..." ...>
[...]
--
Rob
.
- Follow-Ups:
- References:
- Prev by Date: Re: Deselecting text in input text box
- Next by Date: Re: undefined field error message
- Previous by thread: focus after onchange event and regex test not working
- Next by thread: Re: focus after onchange event and regex test not working
- Index(es):
Relevant Pages
|