Reputation: 12224
I have about 50 items on my screen. Each line is a form that contains one select box. Each select box has the same name, "permission_action"
My code:
$("#permission_action").change(function() {
$.ajax({
type: "PUT",
url: this.form.action,
data: "permission[action]=" + $("#permission_action").val()
});
});
only binds to the select box in the first form. I want to bind to all of the items.
Upvotes: 0
Views: 3370
Reputation: 630569
You can bind the ones with the same name, not the same ID, like this:
$("select[name=permission_action]").change(function() {
$.ajax({
type: "PUT",
url: this.form.action,
data: {"permission[action]" : $(this).val() }
});
});
Upvotes: 2
Reputation: 6088
Use CLASS selector instead of ID, as ID suppose to be unique element.
<input class="permission_action" ... />
in javascript
$(".permission_action").change(...);
Upvotes: 5