0

I have function on jQuery who by onclick event send post request and change value in table row.

How i can do it mass? For example, i have button "Check all" on click this, i call function. I want to click-once summoned all the check and then they started to be executed

pseudo code:

<ul>
  <li id=1>text1</li>
  <li id=2>text2</li>
  <li id=3>text3</li>
</ul>

<button id="checkall">check all</button>
<script>

function check(id) { /* ... */ }'

on('click', '#checkall', {
  $("ul li").each(function() { 
    check(this.attr('id'));
  });
});

</script>

Yes, i know thats its stupid idea, but, how i can do it? ^_^

Thanks.

Rafael Herscovici
  • 16,558
  • 19
  • 65
  • 93
Patrick Burns
  • 1,763
  • 6
  • 21
  • 35
  • 9
    Why you used `Threads` word in your title ? – Adil Shaikh Jun 19 '13 at 22:01
  • Are you saying that clicks on individual items send individual (Ajax?) requests - and you've already imlemented this - but you want the "check all" option to send a single (Ajax?) request that includes all of the data at once? Or do you want the "check all" to send multiple requests in a loop? – nnnnnn Jun 19 '13 at 22:01
  • Yes, i say that clicks on individual items send individual (on Ajax) requests, but you want the "check all" to send multiple requests in a loop? – Patrick Burns Jun 19 '13 at 22:06
  • @pXL thought that this is the best word that describes the problem – Patrick Burns Jun 19 '13 at 22:07
  • @AlexKiselev: But WTH do [threads](http://en.wikipedia.org/wiki/Thread_(computing)) have to do with your problem? – Bergi Jun 19 '13 at 22:15
  • can you show your `onclick` function? – Rafael Herscovici Jun 19 '13 at 22:33

2 Answers2

1

You should do it like this :

var check = function() { ... };

$('#checkall').on('click',function() {
  $("ul li").each(function() { 
    check(this);//to check it all use your function
    //other code
  });
});

I used this because I don't know which function are calling and what variable are you passing to.

steo
  • 4,586
  • 2
  • 33
  • 64
  • @roasted - It could be "check" as in "test" (unrelated to checkboxes). But yes, it's not the clearest of questions. – nnnnnn Jun 19 '13 at 22:08
0

The following code will trigger the li's click event (which you said you have already setup)

on('click', '#checkall', {
  $("ul li").trigger('click');
});

You should notice there is a limit on ajax that you can run at the same time, Please view the following How many concurrent AJAX (XmlHttpRequest) requests are allowed in popular browsers?

if you need to run some function before triggering the click, you could do something like this:

$("ul li").each(function() { 
    // Your code here
    $(this).trigger('click');
  });

all in all, i think you are going the wrong way with this.

Community
  • 1
  • 1
Rafael Herscovici
  • 16,558
  • 19
  • 65
  • 93