Jump to content

Archived

This topic is now archived and is closed to further replies.

afrankadvice

Custom jQuery

Recommended Posts

afrankadvice

Hi,

 

I've got a form where the user can select max 3 checkboxes. My setup is like this below. I've added the jQuery script to the custom script area. But for some reason I can select all checkboxes. Can anyone help me?

 

HTML

 

<div id="bla">
    <p>
        Checkbox 1: <input type="checkbox" name="checkme[]" value="1" />
    </p>
    <p>
        Checkbox 2: <input type="checkbox" name="checkme[]" value="2" />
    </p>
    <p>
        Checkbox 3: <input type="checkbox" name="checkme[]" value="3" />
    </p>
    <p>
        Checkbox 4: <input type="checkbox" name="checkme[]" value="4" />
    </p>
    <p>
        Checkbox 5: <input type="checkbox" name="checkme[]" value="5" />
    </p>
    <p>
        Checkbox 6: <input type="checkbox" name="checkme[]" value="6" />
    </p>
    <p>
        Checkbox 7: <input type="checkbox" name="checkme[]" value="7" />
    </p>
    <p>
        Checkbox 8: <input type="checkbox" name="checkme[]" value="8" />
    </p>
</div>
 
jQuery
 
<script>
jQuery(document).jQuery(function() {
$("#bla :checkbox").click(function() {
    if($("#bla :checkbox:checked").length >= 3) {
        $("#bla :checkbox:not(:checked)").attr("disabled", "disabled");
    } else {
        $("#bla :checkbox").attr("disabled", "");
    }
})
});
</script>

Share this post


Link to post
Share on other sites
Aires

Hi afrankadvice

 

I have noticed when I try to add the jquery shorthand ($) in the scripts I write.. DMS does not like it and the script will not work. I would try and remove all the ($) and replace them with jQuery instead and see if the problem persists. 


ndTgvai.jpg

Visit iheartpagelines.com for the latest tutorials on PageLines related products.

 

Share this post


Link to post
Share on other sites
Simon

WordPress runs Jquery like that, you need to change your copy pasted code to use jQuery instead of $, unless you wrap the code in something like this:

(function($) {

    // your code with $ goes in here

}(window.jQuery)

Share this post


Link to post
Share on other sites
afrankadvice

Thanks for your comments. I'm using the code below and it's working

 

<script>
jQuery(document).ready(function() {
jQuery('[name="compare_id[]"]').click(function () {
selected = jQuery('[name="compare_id[]"]').filter(':checked').length;
if (selected > 3){
alert('You may select only 3 questions.');
jQuery(this).attr('checked', false);
}
});
});
</script>

Share this post


Link to post
Share on other sites
Danny

Thanks for informing us the issue has been resolved.


Please search our forums, before posting!

Share this post


Link to post
Share on other sites

  • Similar Content

    • IDdigital
      By IDdigital+
      Hi,
      A site of ours irregularly does not finish loading. The page in question is https://rw360.org/grievance-process/
      In Safari, I'll occasionally get the following error:
      [Error] TypeError: undefined is not an object (evaluating 'a.plModel.init')
          (anonymous function) (site.js:5:91)
          i (jquery.js:2:27455)
          add (jquery.js:2:27750)
          ready (jquery.js:2:29819)
          (anonymous function) (site.js:5)
          Global Code (site.js:5:3421)
      This seems to be a bug in PageLines as far as I can tell. Any suggestions or a fix coming?
      Thanks,
    • Borries
      By Borries+
      I know this is not an easy problem. Maybe there is a easy solution.
      I have tryed to uses the existing solution, that I have found in the forum
      I changed the colours of my nav (simple nav) and the hover effect (a. hover).
      I really tryed to highlight the active/used link in the nav but I cant figure it out.
      I want it to be black when active.
      Any help would be appreciated. Thanks.
      http://www.marcborries.de  nav link: "Sinn & Selbst" 
    • Michael Kummer
      By Michael Kummer+
      Hi guys!
      I am using a plugin called Speed Booster Pack to speed up the load time of michaelkummer.com. One of the plugin settings, Minimize HTML and JavaScript causes an error that I only get with Pagelines. With other themes, such as WordPress' Twenty Seventeen, I do not get that error.
      I have reproduced the problem on my staging site and if you look at the JavaScript console, you will see the following error:
      SyntaxError: Unexpected end of script
      Any clue what PageLines may be doing differently to be contributing to this issue? I contacted the plugin developer and they, of course, pointed me to the theme developer
      Thanks
      Michael
    • flourishdesignstudio
      By flourishdesignstudio+
      Hello,
      We are working on a site and the customers are complaining that the site loads too slowly. They contacted their host who mentioned that the Java Script is all loading at the beginning. Is it possible to delay the load of the less important Java Script until after the initial load to speed up the site? The goal is to load the page faster by minimizing the initial javascript calls.
      Are there any preferred plugins that you would recommend or does this end up causing excessive problems with plugins, etc.?
      Thanks for the help!
    • Dan Haddock
      By Dan Haddock
      Hi Pagelines team and wider community,
      I am looking to develop a single post page for my blog. I have read over an old article on the subject, however the link provided on achieving this goal was giving me security warnings. Is there any way I can get round this?
      Secondly, I have had a root around the .zip file provided on my sites backup, however was unable to locate any file in there with the name of Single.php. Does this file exist in the Pagelines theme?
      By the way, this is the unsafe article: http://support.pagelines.me/docs/customization/create-a-custom-page-template/ (Click at your peril).
       
×