Abhineet.in

unlearning the learnt

Menu
  • Home
  • About
  • CAT Preparation
Menu

Restrict number of selected checkboxes in html

Posted on June 29, 2022April 5, 2023 by Abhineet Mittal

This code will restrict html multi select input to given number.

document.addEventListener( "click", function( event ) {
    if ( event.target.matches( '.input-checkbox' ) ) {
        var inputCheckboxes = document.querySelectorAll( '.input-checkbox[type="checkbox"]:checked' );
        if( inputCheckboxes.length > 3 ) {
            event.preventDefault();
            alert( 'You cannot select more than 3 categories for a post.' );
        }
    }
} );
Category: Coding

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Categories

  • Business
  • CAT Preparation
  • Coding
  • Fiction
  • Finance
  • How-To-Life
  • Javascript
  • Life
  • Life at Infosys
  • Photoshop
  • Productivity
  • Publishing
  • Reading
  • Social Awareness
  • Startup
  • Technology
  • Uncategorized
  • Utilities
  • Visual Studio Code
  • Web Development
  • WordPress
  • Work Culture

Recent Posts

  • Book Review: The Great Gatsby
  • The Ultimate Guide to CAT Preparation: Tips and Tricks
  • Self-Publishing vs. Traditional Publishing: Which Is Right for You?
  • 7 Effective Strategies to Overcome Procrastination and Achieve Your Goals
  • How to detect English/ASCII string in PHP

Recent Comments

  • Rohan George on Intermediate, Stream & Location: Luck by Chance
  • Ashika on Intermediate, Stream & Location: Luck by Chance
  • Steve on My first job, Infosys
  • SAKTHI on Finally, its Mysore…
  • Akash dhyani Akash on Training Begins…
© 2023 Abhineet.in | Powered by Minimalist Blog WordPress Theme