Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #19926

Re: I have a problem

From tony@mountifield.org (Tony Mountifield)
Newsgroups comp.lang.javascript
Subject Re: I have a problem
Date 2013-05-24 15:22 +0000
Organization Software Insight Ltd., Winchester, UK
Message-ID <kno0jp$lj$1@softins.clara.co.uk> (permalink)
References <knnu36$mnl$1@dont-email.me>

Show all headers | View raw


In article <knnu36$mnl$1@dont-email.me>,
Tony <tony.johansson@inport.com> wrote:
> The principle is this when I tab on field with id=fartygID I need to 
> validate this field against table AFARTYG and this is done asynchronously 
> and this can't be changed because of the
> structure of the code.
> 
> If the data.opExist == "False" in function Validate I know that the entered 
> data is invalid and I want the cursor
> to stay in the same field.
> I have tried to use $("#fartygID").focus(); to position the cursor in the 
> fartygID field
> but this does not work.
> 
> It would be easy if I could return the value of data.opExist but this seems 
> to be impossible because of that I use asynchronous call.
> 
> Is it anyone that have any suggestion how I can place the cursor on field 
> with id=fartygID
> if the data.opExist == "False" ?

Try using setTimeout(function() { $("#fartygID").focus(); }, 10);

The 10 is a number of milliseconds to delay before doing the focus. Adjust
as required.

Cheers
Tony


> //Here is the function that validate. check_generic is called asynchronously
> function Validate(ctrlID, ipTable, ipKey, ipKeyValue)
>       {
>           var ipDescriptionField = "";
> 
>           check_generic(ipTable, ipKey, ipDescriptionField, ipKeyValue, 
> function (data, textStatus, jqXHR)
>           {
>               IsOkMessageShort(data.dsError);
> 
>               if (data.opExist == "False")
>               {
>                    $("#fartygID").focus(); //Invalid value don't leave 
> fartygID
>               }
>           });
>       }
> 
> 
> function TabOn_FartygInDialog(e)
>        {
>            var TABKEY = 9;
>            if (e.keyCode == TABKEY)
>            {
>                Validate("fartygID", "AFARTYG", "FARTNR", "", 
> $('#fartygID').val());
> 
> //              this.value += "    ";
> //              if (e.preventDefault)
> //              {
> //                  e.preventDefault();
> //              }
> //              return false;
>             }
>        }
> 
> //Tony 
> 


-- 
Tony Mountifield
Work: tony@softins.co.uk - http://www.softins.co.uk
Play: tony@mountifield.org - http://tony.mountifield.org

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

I have a problem "Tony" <tony.johansson@inport.com> - 2013-05-24 16:43 +0200
  Re: I have a problem tony@mountifield.org (Tony Mountifield) - 2013-05-24 15:22 +0000
    Re: I have a problem "Tony" <tony.johansson@inport.com> - 2013-05-24 17:45 +0200
  Re: I have a problem "Tony" <tony.johansson@inport.com> - 2013-05-24 17:29 +0200
  Re: I have a problem Denis McMahon <denismfmcmahon@gmail.com> - 2013-05-24 22:14 +0000
    Re: I have a problem Christoph Becker <cmbecker69@gmx.de> - 2013-05-25 00:51 +0200
      Re: I have a problem Tim Streater <timstreater@greenbee.net> - 2013-05-25 00:09 +0100

csiph-web