jQuery: The Write Less, Do More JavaScript Library

keyup on textfields

View: New views
5 Messages — Rating Filter:   Alert me  

keyup on textfields

by Denis Caggiano :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
Im new in jQuery, so...

I need the textfields triggers the same function and I have a lot of
them, Im doing this way:

    $('#id_emp').keyup(function(e) {
        if (e.keyCode == 13) {
            $('#busca').click();
        }
    });

    $('#id_bol').keyup(function(e) {
        if (e.keyCode == 13) {
           $('#busca').click();
        }
    });

    $('#ema_pes').keyup(function(e) {
        if (e.keyCode == 13) {
           $('#busca').click();
        }
    });

    $('#nom_emp').keyup(function(e) {
        if (e.keyCode == 13) {
            $('#busca').click();
        }
    });

But Im think that have a better way to do this, like:

    $('ALL_TEXTFIELDS').keyup(function(e) {
        if (e.keyCode == 13) {
            $('#busca').click();
        }
    });

There's something like this?

tks

Re: keyup on textfields

by James-279 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

There are a few simple ways to do this.
Here are probably the most common:

You can assign all the relevant textfields with the same class name:
<input type="text name="text1" class="specialFields" />
<input type="text name="text2" class="specialFields" />

$(".specialFields").keyup(...);


Or you can list all the IDs in the selector:
$("#id_emp, #id_bol, #ema_pes, #nom_emp").keyup(...);

On Oct 30, 7:12 am, onaiggac <denisribe...@...> wrote:

> Hi,
> Im new in jQuery, so...
>
> I need the textfields triggers the same function and I have a lot of
> them, Im doing this way:
>
>     $('#id_emp').keyup(function(e) {
>         if (e.keyCode == 13) {
>             $('#busca').click();
>         }
>     });
>
>     $('#id_bol').keyup(function(e) {
>         if (e.keyCode == 13) {
>            $('#busca').click();
>         }
>     });
>
>     $('#ema_pes').keyup(function(e) {
>         if (e.keyCode == 13) {
>            $('#busca').click();
>         }
>     });
>
>     $('#nom_emp').keyup(function(e) {
>         if (e.keyCode == 13) {
>             $('#busca').click();
>         }
>     });
>
> But Im think that have a better way to do this, like:
>
>     $('ALL_TEXTFIELDS').keyup(function(e) {
>         if (e.keyCode == 13) {
>             $('#busca').click();
>         }
>     });
>
> There's something like this?
>
> tks

Re: Re: keyup on textfields

by Denis Caggiano :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Tks James,
You help me to write a clean code.

Re: Re: keyup on textfields

by Karl Swedberg-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Or, if the OP really wants all text fields to trigger it, he could just use $(':text').keyup( ... )

--Karl

____________
Karl Swedberg




On Oct 30, 2009, at 3:20 PM, James wrote:

There are a few simple ways to do this.
Here are probably the most common:

You can assign all the relevant textfields with the same class name:
<input type="text name="text1" class="specialFields" />
<input type="text name="text2" class="specialFields" />

$(".specialFields").keyup(...);


Or you can list all the IDs in the selector:
$("#id_emp, #id_bol, #ema_pes, #nom_emp").keyup(...);

On Oct 30, 7:12 am, onaiggac <denisribe...@...> wrote:
Hi,
Im new in jQuery, so...

I need the textfields triggers the same function and I have a lot of
them, Im doing this way:

    $('#id_emp').keyup(function(e) {
        if (e.keyCode == 13) {
            $('#busca').click();
        }
    });

    $('#id_bol').keyup(function(e) {
        if (e.keyCode == 13) {
           $('#busca').click();
        }
    });

    $('#ema_pes').keyup(function(e) {
        if (e.keyCode == 13) {
           $('#busca').click();
        }
    });

    $('#nom_emp').keyup(function(e) {
        if (e.keyCode == 13) {
            $('#busca').click();
        }
    });

But Im think that have a better way to do this, like:

    $('ALL_TEXTFIELDS').keyup(function(e) {
        if (e.keyCode == 13) {
            $('#busca').click();
        }
    });

There's something like this?

tks


Re: Re: keyup on textfields

by Denis Caggiano :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Actually, I need only 4 text fields to trigger the function and I have 10. :)
But tks for the hint.