0

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.

1
  • 1
    Do you mean ID? Name is one thing, ID is another. If you have multiple elements with the same ID, that's an issue. It's invalid HTML and you can't select multiple elements by the same ID with jQuery. Commented Nov 16, 2010 at 22:07

3 Answers 3

5

Use CLASS selector instead of ID, as ID suppose to be unique element.

<input class="permission_action" ... />

in javascript

$(".permission_action").change(...);
Sign up to request clarification or add additional context in comments.

Comments

4

Use a class instead of an ID, which should be unique.

Comments

2

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() }
    });  
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.