In article <knnu36$mnl$
1...@dont-email.me>,
Tony <
tony.jo...@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:
to...@softins.co.uk -
http://www.softins.co.uk
Play:
to...@mountifield.org -
http://tony.mountifield.org