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 928699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:03:13+00:00 2026-05-15T20:03:13+00:00

Using ASP.NET to generate several checkboxes. Looking for a JavaScript solution that will test

  • 0

Using ASP.NET to generate several checkboxes. Looking for a JavaScript solution that will test any checkbox starting with the name pdf* to see if more than 5 are checked, then alert over that number.

There are other checkboxes I do not want this to run on that do not have the name pdf*.

Thanks in advance.

here is an example of my checkboxs:

<td><input type="checkbox" name="pdf14" value="2250"></td>

<td><input type="checkbox" name="pdf15" value="2251"></td>

<td><input type="checkbox" name="pdf16" value="2252"></td>
 
<td><input type="checkbox" name="print" value="2253"></td> 

<<<NOT A PART OF THE COUNT

  • 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-15T20:03:13+00:00Added an answer on May 15, 2026 at 8:03 pm
    var inputs = document.getElementsByTagName("input");
    var numSelected = 0;
    var current;
    
    for (var i=inputs.length;i--;) {
        current = inputs[i];
    
        if (current.type.toLowerCase() == "checkbox" && current.checked && current.name.indexOf("pdf") == 0) {
            current++;
        };
    };
    
    if (current > 5) {
        alert("You've got " + current + " selected! :(");
    }
    

    If you happened to use jQuery, it’d be as easy as

    var selectedPdfCheckboxes = $('input:checkbox[name^=pdf]');
    
    if (selectedPdfCheckboxes.length > 5) {
        alert("You've got " + selectedPdfCheckboxes.length + " selected! :(");
    }
    

    Edit:

    The jQuery selector I’ve used (^=) reads as “start with”, so no * equivalent is needed.

    The jQuery code will execute wherever it is placed, however it must be executed no sooner than document.ready(), to ensure the elements you are selecting are present in the DOM. If you place it inside document.ready, it will fire as soon the document ready event is fired. You might want to place the code inside an event handler for another event.. such as the submission of a form?

    $(document).ready(function () {
        $("#aForm").bind('submit', function (e) {
            var selectedPdfCheckboxes = $('input:checkbox[name^=pdf]');
    
            if (selectedPdfCheckboxes.length > 5) {
                alert("You've got " + selectedPdfCheckboxes.length + " selected! :(");
    
                e.preventDefault();        
            }
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a mobile app using ASP.Net MVC to generate HTML 5 pages. The
ASP.NET MVC can generate HTML elements using HTML Helpers, for example @Html.ActionLink() , @Html.BeginForm()
In my ASP.NET MVC application I am using a select list control to generate
I'm using the Rotativa PDF print for an ASP.NET MVC application to generate a
I'm using ASP.NET MVC RC2. I have a set of classes that were auto-generated
I have an ASP.NET MVC application that uses jQuery 1.3.2. On several of the
I have an asp.net 4.0 web site that generates email alerts based on several
I'm reading several docs on validation in ASP.NET MVC . Ignoring those that suggest
I'm using ASP.Net with MVC 3 and trying to auto generate images. In my
I am using asp.net MVC with the asp.net membership but I starting to think

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.