[jQuery] Re: Select all controls of the form

2009-01-13 Thread Karl Rudd

You shouldn't need to use $.extend in this case. Something like this
should work:

jQuery.fn.debug = function() {
  return this.each(function(){
alert(this);
  });
};

Taken from http://docs.jquery.com/Plugins/Authoring

As for your selection code, you need to use "find" instead of
"filter". The "filter" removes non-matching elements, if you pass in a
"form" element then it won't do what you want. The "find" function
works on the child elements of the given elements, which is what you
want.

Karl Rudd

On Tue, Jan 13, 2009 at 7:17 PM, JQueryProgrammer
 wrote:
>
> I want to convert some existing code from traditional javascript for
> loop to $.each. Here is my code:
>
> var oEl = document.getElementById("my_form_id").elements;
>
> for(var i=0; i < oEl.length; i++) {
> //do something
> }
>
> In jquery I have written a $.fn.extend function and the code as:
>
> $.fn.extend({
>test: function() {
>
>//I want to filter only input controls from hte form
>var $this = $(this).filter(":input");
>
>$.each($this, function() {
>//do something
>});
>}
> })
>
> $("#my_form_id").test();
>
> But it is not working.
>
> On Jan 13, 12:05 pm, Karl Rudd  wrote:
>> Errr  elements aren't form controls. 
>> elements are but ":input" selects those. I'm not sure what you mean.
>>
>> Karl Rudd
>>
>> On Tue, Jan 13, 2009 at 5:43 PM, JQueryProgrammer
>>
>>  wrote:
>>
>> > The above code selects all the controls except  tag.
>>
>> > On Jan 13, 11:26 am, Karl Rudd  wrote:
>> >> The '*' selector will select _all_ the nodes (including the s).
>> >> Try using the ':input' selector:
>>
>> >> $("#form1 :input")
>>
>> >>http://docs.jquery.com/Selectors
>>
>> >> Karl Rudd
>>
>> >> On Tue, Jan 13, 2009 at 5:16 PM, JQueryProgrammer
>>
>> >>  wrote:
>>
>> >> > I am trying to validate all the controls that exist in the form. My
>> >> > form code looks like:
>>
>> >> > 
>> >> >
>> >> >
>> >> >
>> >> >
>> >> >
>> >> >Select
>> >> >One
>> >> >Two
>> >> >Three
>> >> >
>> >> >
>> >> >> >> > value="Option1"> Option 1 
>> >> >
>> >> >> >> > value="Option2"> Option 2 
>> >> >
>> >> >Submit
>> >> >Reset
>> >> > 
>>
>> >> > I want to select only the controls of the form viz: textbox, textarea,
>> >> > select, radio & button (Total 7). I am trying to extract them as
>>
>> >> > $("#form1 *").each(function() {
>> >> > alert($("#+this").attr("id"));
>> >> > })
>>
>> >> > it gives me total 16 alerts. I want just 7. Any help..?


[jQuery] Re: Select all controls of the form

2009-01-13 Thread JQueryProgrammer

I want to convert some existing code from traditional javascript for
loop to $.each. Here is my code:

var oEl = document.getElementById("my_form_id").elements;

for(var i=0; i < oEl.length; i++) {
 //do something
}

In jquery I have written a $.fn.extend function and the code as:

$.fn.extend({
test: function() {

//I want to filter only input controls from hte form
var $this = $(this).filter(":input");

$.each($this, function() {
//do something
});
}
})

$("#my_form_id").test();

But it is not working.

On Jan 13, 12:05 pm, Karl Rudd  wrote:
> Errr  elements aren't form controls. 
> elements are but ":input" selects those. I'm not sure what you mean.
>
> Karl Rudd
>
> On Tue, Jan 13, 2009 at 5:43 PM, JQueryProgrammer
>
>  wrote:
>
> > The above code selects all the controls except  tag.
>
> > On Jan 13, 11:26 am, Karl Rudd  wrote:
> >> The '*' selector will select _all_ the nodes (including the s).
> >> Try using the ':input' selector:
>
> >> $("#form1 :input")
>
> >>http://docs.jquery.com/Selectors
>
> >> Karl Rudd
>
> >> On Tue, Jan 13, 2009 at 5:16 PM, JQueryProgrammer
>
> >>  wrote:
>
> >> > I am trying to validate all the controls that exist in the form. My
> >> > form code looks like:
>
> >> > 
> >> >        
> >> >        
> >> >        
> >> >        
> >> >        
> >> >                Select
> >> >                One
> >> >                Two
> >> >                Three
> >> >        
> >> >        
> >> >         >> > value="Option1"> Option 1 
> >> >        
> >> >         >> > value="Option2"> Option 2 
> >> >        
> >> >        Submit
> >> >        Reset
> >> > 
>
> >> > I want to select only the controls of the form viz: textbox, textarea,
> >> > select, radio & button (Total 7). I am trying to extract them as
>
> >> > $("#form1 *").each(function() {
> >> >     alert($("#+this").attr("id"));
> >> > })
>
> >> > it gives me total 16 alerts. I want just 7. Any help..?


[jQuery] Re: Select all controls of the form

2009-01-12 Thread Karl Rudd

Errr  elements aren't form controls. 
elements are but ":input" selects those. I'm not sure what you mean.

Karl Rudd

On Tue, Jan 13, 2009 at 5:43 PM, JQueryProgrammer
 wrote:
>
> The above code selects all the controls except  tag.
>
>
>
> On Jan 13, 11:26 am, Karl Rudd  wrote:
>> The '*' selector will select _all_ the nodes (including the s).
>> Try using the ':input' selector:
>>
>> $("#form1 :input")
>>
>> http://docs.jquery.com/Selectors
>>
>> Karl Rudd
>>
>> On Tue, Jan 13, 2009 at 5:16 PM, JQueryProgrammer
>>
>>  wrote:
>>
>> > I am trying to validate all the controls that exist in the form. My
>> > form code looks like:
>>
>> > 
>> >
>> >
>> >
>> >
>> >
>> >Select
>> >One
>> >Two
>> >Three
>> >
>> >
>> >> > value="Option1"> Option 1 
>> >
>> >> > value="Option2"> Option 2 
>> >
>> >Submit
>> >Reset
>> > 
>>
>> > I want to select only the controls of the form viz: textbox, textarea,
>> > select, radio & button (Total 7). I am trying to extract them as
>>
>> > $("#form1 *").each(function() {
>> > alert($("#+this").attr("id"));
>> > })
>>
>> > it gives me total 16 alerts. I want just 7. Any help..?


[jQuery] Re: Select all controls of the form

2009-01-12 Thread JQueryProgrammer

The above code selects all the controls except  tag.



On Jan 13, 11:26 am, Karl Rudd  wrote:
> The '*' selector will select _all_ the nodes (including the s).
> Try using the ':input' selector:
>
> $("#form1 :input")
>
> http://docs.jquery.com/Selectors
>
> Karl Rudd
>
> On Tue, Jan 13, 2009 at 5:16 PM, JQueryProgrammer
>
>  wrote:
>
> > I am trying to validate all the controls that exist in the form. My
> > form code looks like:
>
> > 
> >        
> >        
> >        
> >        
> >        
> >                Select
> >                One
> >                Two
> >                Three
> >        
> >        
> >         > value="Option1"> Option 1 
> >        
> >         > value="Option2"> Option 2 
> >        
> >        Submit
> >        Reset
> > 
>
> > I want to select only the controls of the form viz: textbox, textarea,
> > select, radio & button (Total 7). I am trying to extract them as
>
> > $("#form1 *").each(function() {
> >     alert($("#+this").attr("id"));
> > })
>
> > it gives me total 16 alerts. I want just 7. Any help..?


[jQuery] Re: Select all controls of the form

2009-01-12 Thread Karl Rudd

The '*' selector will select _all_ the nodes (including the s).
Try using the ':input' selector:

$("#form1 :input")

http://docs.jquery.com/Selectors

Karl Rudd

On Tue, Jan 13, 2009 at 5:16 PM, JQueryProgrammer
 wrote:
>
> I am trying to validate all the controls that exist in the form. My
> form code looks like:
>
> 
>
>
>
>
>
>Select
>One
>Two
>Three
>
>
> value="Option1"> Option 1 
>
> value="Option2"> Option 2 
>
>Submit
>Reset
> 
>
> I want to select only the controls of the form viz: textbox, textarea,
> select, radio & button (Total 7). I am trying to extract them as
>
> $("#form1 *").each(function() {
> alert($("#+this").attr("id"));
> })
>
> it gives me total 16 alerts. I want just 7. Any help..?