tuupola / jquery_chained

Chained Selects for jQuery and Zepto
https://appelsiini.net/projects/chained/
589 stars 283 forks source link

Multiple instances in a form #45

Closed voicecode-bv closed 8 years ago

voicecode-bv commented 8 years ago

Hi there,

Is it possible to have a form with 2 selectboxes, using this plugin while they're both an array?

Like: `

` Hope there is a way to get this working. So far only the first instance is working.
tuupola commented 8 years ago

What have you tried? Can you show the code.

voicecode-bv commented 8 years ago

I'm no hero using jQuery, got as fas as:

$("#product[]").chained("#category[]");

Looping this (nasty) wouldn't do the trick. Just saw some kind of solution in the other issues mentioned earlier. I'll try that out.

tuupola commented 8 years ago

Your HTML does not match above. Atleast your example does not have <select id="product[]">. Also I believe [] are not valid characters in id. They are valid in name though.

voicecode-bv commented 8 years ago

... feeling so stupid right now. Haha. Totally missed out on that one.

tuupola commented 8 years ago

You probably can do something like following:

<select id="category-1" name="category[]"></select>
<select id="product-1" name="product[]"></select>
<select id="category-2" name="category[]"></select>
<select id="product-2" name="product[]"></select>

$("#product-1").chained("#category-1");
$("#product-2").chained("#category-2");
voicecode-bv commented 8 years ago

Jes! Works like a charm. Thanks a lot!