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

  • Home
  • SEARCH
  • 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 7430447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:08:32+00:00 2026-05-29T09:08:32+00:00

I have a form with several ingredients on it. I want a user to

  • 0

I have a form with several ingredients on it. I want a user to be able to select 3 and no more than 3. So if they ticked 3 then the form wouldn’t allow any more but they could untick a choice and pick another.

At the moment though it doesn’t stop a box from being ticked and doesn’t count an untick.

My javascript

<script type="text/javascript">
    var total = 0;
        function check() {
            if( $("input#name").checked = true )
                { 
                    total = total + 1;
                }
            if( $("input#name").checked = false )
                { 
                    total = total - 1;
                }
            if(total > 3)
                {
                    alert("Please Select only three")
                    $("input#name").checked = false ;
                    return false;
                }
        }
</script>

and my form

<form name="ingredientlist" method="post" action="checkboxdone.php">
        <label>Pork</label><input type="checkbox" name="ckb" value="pork" onclick="check();"/><br/>
        <label>Carrot</label><input type="checkbox" name="ckb" value="carrot" onclick="check();"/><br/>
        <label>Whiskey</label><input type="checkbox" name="ckb" value="whiksey" onclick="check();"/><br/>
        <label>Bacon</label><input type="checkbox" name="ckb" value="bacon" onclick="check();"/><br/>
        <label>Leek</label><input type="checkbox" name="ckb" value="leek" onclick="check();"/><br/>
        <label>Potato</label><input type="checkbox" name="ckb" value="potato" onclick="check();"/><br/>
        <input id="button" type="submit" value="Submit" name="button"/>
</form>
  • 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-05-29T09:08:32+00:00Added an answer on May 29, 2026 at 9:08 am

    Plug this into your code and it will run just dandy.

    $(document).ready(function(){
      var totalChecked = 0;
      $('form[name="ingredientlist"] > input[type="checkbox"]').change(function(){
          if (!this.checked) { //unchecking
              totalChecked--;
          } else if (totalChecked < 3) { //checking, with less than 3 checked
              totalChecked++;
          } else { //checking, with 3 checked
              this.checked = false;
          }
      });
    });
    

    http://jsfiddle.net/W9gNg/1/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form where users can pick several locations they want to stay
I'd like to have a form with several select controls in a horizontal (they
I have a form with several text boxes on it. I only want to
I have a form with several buttons on it and when the user presses
I have a form with several groupboxes, each containing controls several checkboxes. I want
I have a form with several textarea elements. User enters data and submits the
I have a form with several submit buttons. I want my last button to
I have a form with several input fields for a User to add their
I have one form with several text fields and one button. When i enter
I have a form that is dynamically created, on this form are several radio

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.