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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:42:55+00:00 2026-05-15T06:42:55+00:00

I am probably going about this all wrong, but here’s what I’m trying to

  • 0

I am probably going about this all wrong, but here’s what I’m trying to do:

I have a form that has approximately 50 select boxes that are generated dynamically based on some database info. I do not have control over the IDs of the text boxes, but I can add a class to each of them. Before the form is submitted, the user needs to select at least one item from the select box, but no more than four.

I’m a little bit sleepy, and I’m unfamiliar with jQuery overall, but I’m trying to override $(“form”).submit, and here’s what I’m doing. Any advice or suggestions are greatly appreciated.

$("form").submit(function() {

    $('.sportsCoachedValidation').each(function() {
        if ($('.sportsCoachedValidation :selected').text() != 'N/A') {
            sportsSelected++
        }                    
    });

    if (sportsSelected >= 1 && sportsSelected <= 4) {
        return true;
    }
    else if (sportsSelected > 4) {
        alert('You can only coach up to four sports.');
        sportsSelected = 0;
        return false;
    }
    else {
        alert('Please select at least one coached sport.');
        sportsSelected = 0;
        return false;
    }
});
  • 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-15T06:42:56+00:00Added an answer on May 15, 2026 at 6:42 am

    OK, here is one other way of perhaps simplifying this further?

    $("form").submit(function() {
    
        // How about avoiding the "each" loop, and just let jQuery count 'em up? (Not actually tested!)
        var sportsSelected = $('.sportsCoachedValidation :selected[value!="N/A"]').length;
    
        if (sportsSelected >= 1 && sportsSelected <= 4) {
            return true;
        }
        else if (sportsSelected > 4) {
            alert('You can only coach up to four sports.');
            return false;
        }
        else {
            alert('Please select at least one coached sport.');
            return false;
        }
    });
    

    Just a thought I had after my last post. It may need some refinement. Hopefully it isn’t a complete failure and is possible for what you’re trying to do. Good luck!

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

Sidebar

Related Questions

This probably has a simple answer, but I must not have had enough coffee
Alright, Im going about this, with what is probably a really complicated solution, but
Probably a long question for a simple solution, but here goes... I have a
This probably sounds really stupid but I have noo idea how to implement jquery's
Okay this is probably a rookie question, but I have never done GUI programming
I'm probably going to be using Tomcat and the Apache Axis webapp plugin, but
Sometimes I come across this problem where you have a set of functions that
I have the following code. My intention that this custom object can be cast
In .NET 3.5, I'm going to be working with System.Reflection to use AOP (probably
Probably a really simple one this - I'm starting out with C# and need

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.