Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9179729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:52:23+00:00 2026-06-17T17:52:23+00:00

I have hacked together this jQuery script and it is all working fine except

  • 0

I have hacked together this jQuery script and it is all working fine except that the alert is being fired when it shouldn’t be, and I can’t work out why.

jQuery(document).ready(function(){              
function countDouble() {      

  var d = $("input.double:checked").length;
  var s = $("input.single:checked").length;

    if (s === 1 && d === 2) {

        $("a#proj-btn").attr("href", "#tab2");

    } else {

        $("a#proj-btn").attr("href", "http://www.someurl.com.au/new-cruise-name-home");
        $("#proj-btn").click( function() {
            alert('Please select which projects you are interested in before continuing with enquiry.\nSelect 1 x 1 day project and 2 x 2 day projects by ticking the box beneath your chosen projects.');
        });
    };
}
countDouble();
$(":checkbox").click(countDouble);  
}); 

Here is the HTML

<ul class="tabs">
    <li class="right"><a id="proj-btn" href="#">NEXT &gt;&gt; Cabin Choice</a></li>
</ul>

So when there is 1 x .single checkbox checked and 2 x .double checkboxes checked, it adds the URL of #tab2 to the button which works fine.
But it also displays the alert 3 times after clicking the button when the checkboxes are checked. The alert should only be when the checkboxes are not checked.
What have I done wrong? I can’t work this out

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T17:52:24+00:00Added an answer on June 17, 2026 at 5:52 pm

    Try Unbinding ‘click’ every time you call countDouble() and pulling countDouble() outside of the ready function (probably not necessary).

    function countDouble() {      
      var d = $("input.double:checked").length;
      var s = $("input.single:checked").length;
    
      //Add This:
      $("#proj-btn").unbind('click');
    
      if (s === 1 && d === 2) {
    
            $("a#proj-btn").attr("href", "#tab2");
    
      } else {
    
            $("a#proj-btn").attr("href", "http://www.someurl.com.au/new-cruise-name-home");
            $("#proj-btn").click( function() {
                alert('Please select which projects you are interested in before continuing with enquiry.\nSelect 1 x 1 day project and 2 x 2 day projects by ticking the box beneath your chosen projects.');
            });
      };
    }
    jQuery(document).ready(function(){              
        countDouble();
        $(":checkbox").click(countDouble);  
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this chunk of javascript that's kind of hacked around from http://www.developphp.com/view.php?tid=1248 and
I hate code that looks like its been hacked together. I have just written
This partial code I hacked in to JamieMThomas's JQuery plugin that combines the Microsoft
I'm using DataTables and have hacked together this somewhat embarrassing Javascript to allow row
I am working on a jQuery-based todo list interface, and have hit a bit
Newbie to jquery here... I have 2 jquery scripts that attach to 1 div.
I have a little php/mysql app I put together that takes an input form
As a learning exercise I've hacked together a script for an SO feature request
The light box pops up, but doesn't load the image. I have hacked this
This has to be the biggest nuisance I've encountered with PyQT: I've hacked together

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.