In addition to Wizzud's solution:
Since it seems that you want to be able to access each select with the
name "foo" individually and change their values individually you could
try something like this:

$('select[name=foo]').each(function(i){
          $(this).addClass('foo'+i);
          });

This would dynamically add classes foo0, foo1, foo2, etc. to your
selects named foo, meaning you could access each by class name if you
know what order they appear in. Also, make sure to run that script
whenever the contents of your table change so you always have an up to
date list. I assume it would be 'better' to give id's to each one
since they are unique, but unique class names work just as well and
there is no addId method in jQuery.

On Oct 5, 5:59 pm, Wizzud <[EMAIL PROTECTED]> wrote:
> With...
> <select name='foo'><option value='bar1'>bar1</option></select>
> <select name='foo'><option value='bar2'>bar2</option></select>
>
> ....try...
> var selects = $('select[name=foo]');
>
> See the Attribute Filters, under Selectors in the API Reference.
>
> (If you have non-unique ids for elements on your page, do not rely on
> selecting them by $('#id')!)
>
>
>
> syg6-2 wrote:
>
> > For reasons I won't go into here I have a page which has a table with
> > a variable amount of rows. Each row has a hidden, text, and select.
> > They all have the same name. I also have other selects on the page
> > with different names.
>
> > What I need to do is access only the selects, to be able to add and
> > remove options. So I need to know how many selects with the name "foo"
> > are on the page
>
> > I have tried this:
>
> > jQuery("select#foo")
>
> > which simply returns [Object object]. If I do this:
>
> > jQuery("select#foo").length
>
> > it returns 0 which is not true. When I load the page I have 2 selects
> > already. So if I do this:
>
> > jQuery("select#foo").text()
>
> > it returns white space. And
>
> > jQuery("select#foo").val()
>
> > returns undefined.
>
> > I have also tried stuff like
>
> > jQuery("select#foo[0]").val()
>
> > but nothing seems to work. Since uses can dynamically add rows to the
> > table (and with each one a hidden, text input and select) I need to 1)
> > know how many selects with a given id/name there are and 2) be able to
> > manipulate the values in each one.
>
> > How can I do this?
>
> > Thanks!
>
> --
> View this message in 
> context:http://www.nabble.com/multiple-selects%2C-hiddens-and-text-inputs-wit...
> Sent from the jQuery General Discussion mailing list archive at Nabble.com.

Reply via email to