Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

I have a problem

4 views
Skip to first unread message

Tony

unread,
May 24, 2013, 10:43:43 AM5/24/13
to
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" ?

//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

unread,
May 24, 2013, 11:22:33 AM5/24/13
to
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

Tony

unread,
May 24, 2013, 11:29:14 AM5/24/13
to
I solved it by first using blur
and then in the function called from blur use focus

//Tony

"Tony" wrote in message news:knnu36$mnl$1...@dont-email.me...

Tony

unread,
May 24, 2013, 11:45:55 AM5/24/13
to
Yes now it works perfect
many thanks Tony Mountifield

//Tony

"Tony Mountifield" wrote in message news:kno0jp$lj$1...@softins.clara.co.uk...

Denis McMahon

unread,
May 24, 2013, 6:14:37 PM5/24/13
to
On Fri, 24 May 2013 16:43:43 +0200, Tony wrote:

> $(

jquery detected, please ask in a jquery forum.

--
Denis McMahon, denismf...@gmail.com

Christoph Becker

unread,
May 24, 2013, 6:51:03 PM5/24/13
to
Denis McMahon wrote:
> On Fri, 24 May 2013 16:43:43 +0200, Tony wrote:
>
>> $(
>
> jquery detected, please ask in a jquery forum.

How so? I am just detecting the beginning of a CallExpression with the
MemberExpression being the identifier $.

--
Christoph M. Becker
Message has been deleted
0 new messages