Wizzud
Thank you *very* much. Your solution works fine.
Paul

On 8 Jun, 08:47, Wizzud <[EMAIL PROTECTED]> wrote:
> Try adding...
>
> $(':text').bind('focus', function(){
>     hasFocus = $(this);
>   });
>
> On Jun 5, 7:43 pm, paulj <[EMAIL PROTECTED]> wrote:
>
> > Wizzud, thank you for your help.
>
> > Your code worked perfectly if the user had entered the text box by
> > *clicking* on it.
> > But, if the user has *tabbed* to the text box (and then clicks on
> > another element) the focus is returned to the text box that was last
> > *clicked* on.
> > This can be seen in my example HTML.
>
> > Thank you (or others) for any fine-tuning on this.
>
> > Paul
>
> > On 5 Jun, 09:54, Wizzud <[EMAIL PROTECTED]> wrote:
>
> > > Any good for you ... ?
>
> > > $(document).ready(function(){
> > >   var hasFocus = $(':text:first').focus();
> > >   $(document).bind('click', function(event){
> > >     var ev = $(event.target);
> > >     if(ev != hasFocus){
> > >       if (ev.is(':text')){
> > >         hasFocus = ev;
> > >       }
> > >       hasFocus.focus();
> > >     }
> > >   });
>
> > > });
>
> > > On Jun 5, 2:30 am, paulj <[EMAIL PROTECTED]> wrote:
>
> > > > Hi,
>
> > > > When a text box has the focus, I would like it to keep the focus even
> > > > when another element type (not another text box) is clicked. eg after
> > > > clicking this other element type, the user can press a key(s) and the
> > > > text box will accept this key input without the user having to click
> > > > back into the text box.
> > > > Hope this makes sense.
>
> > > > Karl gave me some info. the other day and I was pretty sure I would be
> > > > able to fine-tune it for my app. but the best I could come up with
> > > > is :
>
> > > > $(document).ready(function()
> > > > {
> > > >   $(':text').blur(function(event)
> > > >   {
> > > >       if (!$(event.target).is(':text'))
> > > >       { $(this).focus() }
> > > >   });
>
> > > > });
>
> > > > Thanks for any help
> > > > Paul
>
> > > > Here is the full code :
>
> > > > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/
> > > > TR/html4/strict.dtd">
> > > > <html>
>
> > > > <head>
>
> > > > <title></title>
> > > > <meta http-equiv="Content-Type" content="text/html;
> > > > charset=ISO-8859-1">
>
> > > >       <style type="text/css">
> > > >       input { width : 700px ; }
>
> > > >       </style>
>
> > > >  <script type = "text/javascript" src="jquery.js"></script>
> > > >  <script type = "text/javascript">
>
> > > > $(document).ready(function()
> > > > {
> > > >   $(':text').blur(function(event)
> > > >   {
> > > >       if (!$(event.target).is(':text'))
> > > >       { $(this).focus() }
> > > >   });
>
> > > > });
>
> > > >  </script>
>
> > > > </head>
>
> > > > <body>
>
> > > > <ul>
> > > > <li>click here</li>
> > > > <li>or click here</li>
> > > > </ul>
>
> > > > <br> <br>
>
> > > > <form>
>
> > > >  <input type='text' class='test' value='these text boxes should retain
> > > > the focus when another element type is clicked'> <br><br>
> > > >  <input type='text' value='these text boxes should retain the focus
> > > > when another element type is clicked'> <br><br>
> > > >  <input type='text'   value='these text boxes should retain the focus
> > > > when another element type is clicked' id='focusHere'> <br>
>
> > > > </form>
>
> > > > </body>
>
> > > > </html>

Reply via email to