Jared
Jared

Reputation: 4615

Get group of checkboxes by name attribute in ExtJS

I am trying to get a group of checkboxes by the name attribute. For example, I have the following:

<input name="labs[]" type="checkbox" value="lab1" />
<input name="labs[]" type="checkbox" value="lab2" />
<input name="labs[]" type="checkbox" value="lab3" />
<input name="labs[]" type="checkbox" value="lab4" />

And Im trying to get that group by doing something like:

Ext.query('input[name=labs[]]');

But that clearly doesn't work because of the square brackets that are part of the name. I'm lost as to how to do this?

Upvotes: 0

Views: 1706

Answers (2)

JamesHalsall
JamesHalsall

Reputation: 13475

Try matching an input element that has a name attribute that starts with 'labs':

Ext.query("input[name^=labs]");

Upvotes: 0

McStretch
McStretch

Reputation: 20645

You could do a "starts with" match instead:

Ext.query('input[name^=labs]');

This will not work very well if you have other elements that start with "labs" though, so you may want to add another identifier to your "labs[]" name, i.e. "labs-check[]".

Upvotes: 3

Related Questions