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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:53:17+00:00 2026-05-14T06:53:17+00:00

I have a personal details form that allows you to enter a certain number

  • 0

I have a personal details form that allows you to enter a certain number of dependants which is determined by the JSP application.

The first dependant is visible and the user has the option to add dependants up to the maximum number. All other dependants are hidden by default and are displayed when a user clicks the ‘Add another dependant button’.

When the maximum number of dependants has been reached the button is greyed out and a message is generated via jQuery and displayed to tell the user exactly this.

The issue I am having is when the maximum number of dependants has been reached the message is displayed but then the user can click the button to add more dependants and the message keeps on generating.

I thought unbinding the click event would sort this but it seems to still be able to generate a second message.

Here is the function I wrote to generate the message:

    // Dependant message function
function maxDependMsg(msgElement) {
    // number of children can change per product, needs to be dynamic
    // count number of dependants in HTML           
    var $dependLength = $("div.dependant").length;  
    
    // add class maxAdd to grey out Button
    // create maximum dependants message and display, will not be created if JS turned off
    $(msgElement)
    .addClass("maxAdd")
    .after($('<p>')
    .addClass("maxMsg")
    .append("The selected web policy does not offer cover for more than " + $dependLength + " children, please contact our customer advisers if you wish discuss alternative policies available."));
}

There is a hyperlink with a click event attached like so:

    $("a.add").click(function(){
    
    // Show the next hidden table on clicking add child button
    $(this).closest('form').find('div.dependant:hidden:first').show();
            
    // Get the number of hidden tables
    var $hiddenChildren = $('div.dependant:hidden').length;
            
    if ($hiddenChildren == 0) {
    
        // save visible state of system message 
        $.cookies.set('cpqbMaxDependantMsg', 'visible');
        
        // show system message that you can't add anymore dependants than what is on page
        maxDependMsg("a.add");
        
        $(this).unbind("click");
                    
    } 
            
    // set a cookie for the visible state of all child tables   
    $('div.dependant').each(function(){
                
        var $childCount = $(this).index('div.dependant');
                
        if ($(this).is(':visible')) {
            $.cookies.set('cpqbTableStatus' + $childCount, 'visible');
        } else {
            $.cookies.set('cpqbTableStatus' + $childCount, 'hidden');       
        }
        
    });
            
    return false;
});

All of the cookies code is for state saving when users are going back and forward through the process.

  • 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-14T06:53:17+00:00Added an answer on May 14, 2026 at 6:53 am

    Make sure it really counts your hidden divs, debug with console.log($hiddenChildren); or alert($hiddenChildren);. Also you really don’t need to unbind the function and bind it again. Just use return false; instead $(this).unbind("click");. Thing is i’m not sure :hidden matches elements that just have display: hidden; or they have to be hidden with .hide();. Keep in mind that :hidden also matches <input type="hidden" /> so if you have such filter them using :not(). Hope this helps you resolve your problem.

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

Sidebar

Related Questions

I have a details Form with multiple textviews (label: field) that are added with
I have a project that inserts personal information to a table and details into
I have a usecase which describes like : Candidates register their details like personal,
I have created a number of personal libraries to help with my daily coding.
I have a Perl script I wrote for my own personal use that fetches
I have an ASP.NET wizard where a user fills in their personal details and
I have this situation: I have an entity, Person , that contains all personal
Hello All, I have a form which have 5 step and in final step
I have a HTML page with personal information details using text boxes. I have
I have a form and as a result of that form I have two

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.