views:

78

answers:

4
A: 

How about JQuery's click method?

middus
+1  A: 

You can't/shouldn't invoke that code directly. You can fire off the click event, though, which will cause the inline onclick code to be called.

$("#the_thing").click();

You could probably have managed to execute the code "directly" by converting it to a string and doing evals, but invoking it indirectly with the click event is a lot better imo.

August Lilleaas
bottom line I could do: $(this).attr('checked', $("#ckbSelectAll").attr('checked')).click(); ... when the click() executes I still do not have that input box checked ... not even if I put it in a new line as $(this).click();
balexandre
It will be checked. But how is that related anyway?
August Lilleaas
That is, it will be checked if you checked it successfully. If it isn't checked in your case, it's because you didn't do it right. Double check that `$("#ckbSelectAll").attr('checked')` returns what you think it returns, etc.
August Lilleaas
can you be so kind and see this Screencast ( http://tr.im/yey2 ), when that event fires, you can see that the element is not yet checked.
balexandre
the same screencast with the click commented: it does check all inputs ( http://tr.im/yez0 )
balexandre
Perhaps you're confused by the fact that the `click` event causes the box to be un-checked if it was checked; clicking a checkbox is what causes it to change state. Take a look at this: http://august.lilleaas.net/_demo/stuff/click_event_on_checkboxes.html. I circumvent changing state by returning false. Not sure how you would be able to do that with your in-line scripts, though..
August Lilleaas
the only difference that you have is that you specify "checked" and I pass true or false as you can as well to check / uncheck like: $("input").attr("checked", false)
balexandre
You're not an easy person to help. As I mentioned, `return false;` is probably the key here - e.g stopping the event from running, causing the checkbox to not be checked when running the click event.
August Lilleaas
A: 

To directly answer your question:

Remove javascript: from the onclick: it's only meant to be for protocol definitions on hrefs.

To indirectly answer your question:

There's nothing in that page that couldn't be executed without sticking Javascript in the attributes of the HTML. Try:

  • Looping through all checkboxes;
  • For each checkbox, grab the contents with things like: $(this).text(); $(this).val(); etc.
  • Set them to checked with: $(this).attr('checked', 'checked');
Brad Wright
I already do this, as $(this).attr('checked', true); I need to execute the click event, but soon as executes that input is not yet checked as the code should do it before, please see August comments as I added 2 screencasts, thank you.
balexandre
A: 

found it...

I don't need to select all checkboxes prior to the fire the click event, as the jQuery method click() will literally click the checkbox and if is not checked it will check and vice versa

the SelectAll method will only need to be:

  $("#ulworksites li input:checkbox").each(function() {
     if ($(this).attr('disabled') == false) {
        $(this).click();
     }
  });

will work for all (check and uncheck) as you can see in this screencast

http://tr.im/yeTS

balexandre