Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: Re: Problem with OnBlur


Message #1 by "Chris Scott" <chris@e...> on Thu, 1 Aug 2002 18:36:51 +0100
Or you could use the onchange event.  The problem with events like that is 
that they are fired every time a key is pressed, so if user wanted to type 
in '1234' the event would fire 4 times - how would you know when they had 
finished entering data in that field?

I don't know if this is appropriate for what you're trying to do, but 
alternatively you could move the validation out of the onblur() and 
validate all fields when the user tries to take any action, e.g. clicking 
submit button. 

HTH
Phil
>-------------------------------------
You could use the onkeyup event to trap the individual key strokes.

HTH,

Chris
>-------------------------------------
> Hi,

> I have a form which uses an onBlur event to run Javascript validation on
> text inputs.
>
> This is air code (not tested)
> <input type=text name=text1 value="1" onblur="validate(this)"
> <input type=text name=text2 value="2" onblur="validate(this)"
>
> <script>
> function validate(o)
> alert(o.value)
> return
> </script>
>
> The construct I use is something similar but some also then launch 
popups.
> My problem is that this code quite happily alerts "1" press a key then it
> alerts 2 then 1 and so on without letting me input anything. This means I
> have to close the browser task before I can do anything.
>
> My question that by the time onBlur runs focus has already moved to the
> next control in sequence therefore the alert then triggers that ones
> onBlur. In other program languages I have a method that fires before the
> focus is moved. Does Javascript have anything similar? or is it possible
> to turn off events on the form while I run validation then turn them on
> again.

  Return to Index