0
<input 
    type="checkbox" 
    onclick="ToggleAllItems(event,this,12)" 
    title="Select or deselect all items" 
    class="s4-selectAllCbx"
>

How can I set var i = 15 to the onclick attribute instead of 12?

It should be changed after the PageLoad.

4
  • What task are you trying to complete by doing this? There may be an easier way than mucking around with the value of an onclick attribute. Commented Apr 4, 2014 at 2:14
  • Could you show the ToggleAllItems code. Commented Apr 4, 2014 at 2:16
  • @ajp15243: I need to split the onclick away and then add it again to my code. However, the "12" is not a solid number, I need to set "15" or another number to this. Commented Apr 4, 2014 at 2:18
  • @dbh: It calls a js file which has a large amount of code. As a result, I do not want to change anything from that file. Commented Apr 4, 2014 at 2:20

3 Answers 3

1

EDITED TO FIX MISTAKE

In Jquery you can try this:

$("#id").attr("onclick","ToggleAllItems(event,this," + i + ")");

It would take the onclick attribute and rewrite its value, so you can change the third parameter to i.

Note:

You would have to make sure this attr change happens before the onclick event executes.

Sign up to request clarification or add additional context in comments.

7 Comments

change onclick="ToggleAllItems(event,this,12)" to onclick="ToggleAllItems(event,this,15)". I just want to make sure that this has been changed before the onclick event executes.
Place my code into $(document).ready(function() { "CODE GOES HERE" }); document ready runs on page load. Change i in my code to whatever you want the number to be, e.g 15
That's great. I have tried it but the i was i, it wasn't as anything I expected. var i = number (number here can be 15,20,25,30...)
place the var i = number as the first line in the document.ready function
Oh sorry. Mental blank.... $("#id").attr("onclick","ToggleAllItems(event,this," + i + ")");
|
1

Why not removing the onclick property and adding yours... LIKE THIS FIDDLE

$('.s4-selectAllCbx').prop('onclick', '');
$('.s4-selectAllCbx').on('click', function (event) {
    ToggleAllItems(event, this, 15)
})

5 Comments

Thank you for your code. However, it should be changed before the onclick event executes.
So you can't do all of when the page loads? Remove the current onclick and add yours?
@vyx.ca: When the page loads, I can extract "15" from another attribute and then Can I add the number to the onclick event before it executes?
@vyx.ca: What do you mean here?
That was what I was saying. When the page loads, you replace all the current onclick events with the information you want. This will happen before the user clicks on the button so the initial code will not run, only the new one you created.
0

I'm not sure if this answers your question. Please don't use onclick attribute if you will to put data.

$("#yourinputid").click(function(e) {
    var event = e;
    var element = this; // your "this" will be element.
    var i = 15;

    //paste you ToggleAllItems() code here.
});

6 Comments

Thank you for your response but the ToggleAllItems() was a function of SharePoint. Therefore, I am attempting to split it away and try to add it again in order to make sure that it runs as it's own SharePoint's function.
Ok, I'm guessing here. What if, $("#yourinputid").click(function(e) { var i = 15; ToggleAllItems(e,this,i) });
As a quick glance, does it run after the executing of the checkbox's onclick event?
Thank you. Yet what I need here is it is automatically changed after the PageLoad. When I use the onclick event that runs another function.
So you want to change the element's 'onclick' property? or you just want to change the 12 to 15?
|

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.