Support » Plugins and Hacks » [Resolved] [Plugin: Football Pool] max select checkboxe

[Resolved] [Plugin: Football Pool] max select checkboxe

  • hello,

    Im busy to create a rule for each question to setup max select checkbox at multiple choise questions.
    I did edit the admin file so i do write max select to the database.

    Only i do need get it working now on the prediction page.

    i did found/edit the following code:

    $("#q23 :checkbox").click(function() {
        if($("#q23 :checkbox:checked").length >= 4) {
            $("#q23 :checkbox:not(:checked)").attr("disabled", "disabled");
        } else {
            $("#q23 :checkbox").attr("disabled", "");

    at: http://jsfiddle.net/r6KYu/

    and put it into the pool.js. but it seems the js isnt loading.
    Does anyone experimented with this too?


Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author AntoineH


    I don’t know if it helps, but: in WordPress you have to use jQuery instead of $.

    jQuery("#q23 :checkbox") etc.

    do you know it that is enough? just editing the pool.js file or do i have to edit the php as well?

    Plugin Author AntoineH


    If you’re doing everything with jQuery my guess would be that you won’t have to edit the php. But I don’t know what more custom code or database changes you made.

    well .. did a clean football pool install with only the code above for checking the checkbox limit.

    didn’t work 🙁 so i have to figure it out which part i have to change to read the right div.

    Plugin Author AntoineH


    I tried your code with removeAttr instead of setting the disabled attribute to an empty string and that worked for me.

    The code must be inside the document-ready function. E.g.:

    jQuery( document ).ready( function() {
    	jQuery("#q1 :checkbox").click(function() {
    		if(jQuery("#q1 :checkbox:checked").length >= 2) {
    			jQuery("#q1 :checkbox:not(:checked)").attr("disabled", "disabled");
    		} else {
    			jQuery("#q1 :checkbox").removeAttr("disabled");
    	// set some default Highchart options
    	etc. etc.

    i’ve added this code

    // multiple choice max select
    	jQuery("#q1 :checkbox").click( function() {
        	if(jQuery("#q1 :checkbox:checked").length >= 2) {
            	jQuery("#q1 :checkbox").not(":checked").prop("disabled", true);
        	} else {
            	jQuery("#q1 :checkbox").not('checked').prop("disabled", "");

    But after reloading the page you can select a new checkbox. Then the others will be disabled. after reloading again you can select a new checkbox.

    Plugin Author AntoineH


    Then you have to do the check also on page-load. I added 2 functions in my pool.js file in the development version (set_max_answer and check_max_answer).

    If you add a set_max_answer line for each question (example included at the top of the file), then everything should be fine.

    Still, it would be better to handle this server-side, because javascript can always be disabled. But this is a start.
    If someone would want to go through all this trouble and manages to post more than the max answers, then just give this user 0 points in the admin. No hacking allowed 😉

    hehe good option 🙂

    yes thats a start but we have an another challenge with this part. The div and the length is dynamic and it would be nice to set the restriction in the question at the adminpanel. So we need the put data from the database into the jQuery/javascript. AJAX would be a great option.

    btw did add you code but dont understand which function checks the selected boxed on pageload

    Plugin Author AntoineH


    set_max_answer does this for you: it checks on page-load and it sets the click action. So you only have to call this single function.

    Yes, it would be better to do this automatically via the questions admin. But I’m not planning any extra features so I won’t be programming it. 🙂
    If you think about it. How many times will the max number for a given question change? Not many times, probably not even once during the tournament. So, for now, I think this work-around should work just fine.
    The div for a question is fixed for that question, so if you set the javascript for a question once the question is added to the database, then you won’t have to change it anymore; the database ID remains the same.

    If you’re going for the javascript-only solution I suggest that you use a plugin that enables you to dynamically add javascript to your pages. That way you won’t have to fiddle with the plugin code and risk losing changes in an update.
    I don’t know which one is best, but I tried “HTML Javascript Adder“, added the widget to one of my sidebars and added the following lines in the widget:

    <script type="text/javascript">
    jQuery( document ).ready( function() {
    	set_max_answers( 1, 2 ); // question ID 1 has a max of 2
    	set_max_answers( 5, 4 ); // question ID 5 has a max of 4

    That was it to maximize two of my questions.

    Disclaimer: Plugin version 1.4 does not contain the needed functions. They have to be taken from the development tree. A future release (e.g. 1.4.1) will contain the changed pool.js.

    i think you’re right. Will configure that work-around for now but i see it as a challenge 🙂

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘[Resolved] [Plugin: Football Pool] max select checkboxe’ is closed to new replies.