[jQuery] Re: How do I get the index of the currently clicked textbox?

2009-02-02 Thread Mauricio (Maujor) Samy Silva


Hi Bittermonkey,
There is a great explanation with examples on jQuery documentation.
Please have a look at:
http://docs.jquery.com/Utilities/jQuery.each#objectcallback

Good luck
Maurício

-Mensagem Original- 
De: "bittermonkey" 

Para: "jQuery (English)" 
Enviada em: segunda-feira, 2 de fevereiro de 2009 19:05
Assunto: [jQuery] Re: How do I get the index of the currently clicked 
textbox?




Stephan, that was a good suggestion but I'm trying to minimize HTML
code because the page I am working on is asp.net.  That's a useful
trick to know.

Mauricio it worked like a charm.  Thank you so much.  If you don't
mind, can you briefly explain why function(i) seems to know the
element's index?

On Feb 2, 3:08 pm, "Mauricio \(Maujor\) Samy Silva"
 wrote:

Try:

$('input[type=text]').each(function(i) {
$(this).click(function() {
alert(i);
});
});

Maurício

-Mensagem Original-
De: "bittermonkey" 
Para: "jQuery (English)" 
Enviada em: segunda-feira, 2 de fevereiro de 2009 17:47
Assunto: [jQuery] How do I get the index of the currently clicked textbox?



> Hi,

> How do I get the index of the currently clicked textbox? I have 5
> textboxes in a form, all of which I am binding a click event. Here is
> the code:

> $("#associate-form input[type=text]").bind("click", function()
> {
> alert(this); //what is its index position from the 5
> other textboxes?
> });

> Thanks in advance. 




[jQuery] Re: How do I get the index of the currently clicked textbox?

2009-02-02 Thread bittermonkey

Stephan, that was a good suggestion but I'm trying to minimize HTML
code because the page I am working on is asp.net.  That's a useful
trick to know.

Mauricio it worked like a charm.  Thank you so much.  If you don't
mind, can you briefly explain why function(i) seems to know the
element's index?

On Feb 2, 3:08 pm, "Mauricio \(Maujor\) Samy Silva"
 wrote:
> Try:
>
> $('input[type=text]').each(function(i) {
>   $(this).click(function() {
>    alert(i);
>   });
>  });
>
> Maurício
>
> -Mensagem Original-
> De: "bittermonkey" 
> Para: "jQuery (English)" 
> Enviada em: segunda-feira, 2 de fevereiro de 2009 17:47
> Assunto: [jQuery] How do I get the index of the currently clicked textbox?
>
>
>
> > Hi,
>
> > How do I get the index of the currently clicked textbox?  I have 5
> > textboxes in a form, all of which I am binding a click event.  Here is
> > the code:
>
> >        $("#associate-form input[type=text]").bind("click", function()
> > {
> >            alert(this);  //what is its index position from the 5
> > other textboxes?
> >        });
>
> > Thanks in advance.


[jQuery] Re: How do I get the index of the currently clicked textbox?

2009-02-02 Thread Mauricio (Maujor) Samy Silva


Try:

$('input[type=text]').each(function(i) {
 $(this).click(function() {
  alert(i);
 });
});

Maurício

-Mensagem Original- 
De: "bittermonkey" 

Para: "jQuery (English)" 
Enviada em: segunda-feira, 2 de fevereiro de 2009 17:47
Assunto: [jQuery] How do I get the index of the currently clicked textbox?




Hi,

How do I get the index of the currently clicked textbox?  I have 5
textboxes in a form, all of which I am binding a click event.  Here is
the code:

   $("#associate-form input[type=text]").bind("click", function()
{
   alert(this);  //what is its index position from the 5
other textboxes?
   });

Thanks in advance. 




[jQuery] Re: How do I get the index of the currently clicked textbox?

2009-02-02 Thread Stephan Veigl

How about writing the index of the textbox into it's name attribute
(or another attribute) and then get the index by
  var index = $(this).attr("name");

by(e)
Stephan

2009/2/2 bittermonkey :
>
> Hi,
>
> How do I get the index of the currently clicked textbox?  I have 5
> textboxes in a form, all of which I am binding a click event.  Here is
> the code:
>
>$("#associate-form input[type=text]").bind("click", function()
> {
>alert(this);  //what is its index position from the 5
> other textboxes?
>});
>
> Thanks in advance.