tags:

views:

41

answers:

2

using jQuery, I am trying to get an action assigned to a button on a form. I have 50 of these forms on a page, but every time I click one link, the form action is run 50 time!!

I ran this to check, and it comes to exactly 50

  `i=1
      $('.thumbs').click(function(){
        console.log(i,"Click Count");
        i++;
)};

this has the unhelpful effect of running the AJAX fifty times!!

am I using selectors wrong?

EDIT: full script here

EDIT: Example of one element - There are 50 of these inside a container div.

A: 

Are you adding the listener to a submit button? Make sure to return true or false if the form should be submitted or not.

EMMERICH
false is returned - see http://pastebin.com/X9TA0NQj for full script
Mild Fuzz
Feel like uploading the HTML?
EMMERICH
@EMMERICH See the second edit to the question.
Mild Fuzz
Have you tried setting the listener on the form, instead of the input? So `$('.voter').submit(function () { // your submit code here });`.I think it might be caused because, in your code, you're not returning false on the form, you're returning false on the button click (so the submit may go through, not sure of the order of events).
EMMERICH
http://pastebin.com/wv1ahwiE still same deal, running 50 times
Mild Fuzz
A: 

it sounds like it could be one of there two: 1) you've added 50 click listners to one button: you could try this by adding:

$('.thumbs').unbind();

before you assign a new handler.

If this is the case, you should try to find out why and make sure you only add one.

2) the button default action is the problem:

stop default behavior:

$('.thumbs').click(function(event){
event.preventDefault();
Milo
for no good reason, it stopped behaving the way it was. Then it started again!! I added this, and it's fixed, I am so confused!!
Mild Fuzz