troubleshooting Question

Show maximum 4 forms on user actions

Avatar of Yakup K
Yakup K asked on
JavaScriptjQuery
9 Comments2 Solutions92 ViewsLast Modified:
I have got a form shown on the page at first. Then I would like to show another 3 forms , on the user actions.

jsfiddle

   <div id="form-0">

    form 0
    </div>

    <div id="form-1" class="add-form">
    <a class="remove-form">X</a>
    form 1
    </div>

    <div id="form-2" class="add-form">
    <a class="remove-form">X</a>
    form 2
    </div>

    <div id="form-3" class="add-form">
    <a class="remove-form">X</a>
    form 3
    </div>


<p class="request-text">Maximum of 4 per request</p>
<a href="#" class="add-another-form">+ Add another form </a>


$("a.remove-form").bind("click", function(e) {
    	    $(e.target).closest(".add-form").css("display", "none");
});

counter = 0;

   function checkCounter() {
          if (counter > 4)
          {
            $('.request-text').text('You have reached maximum 4 requests ');
            $(".request-text").css("color", "green");                
            $('.add-another-form').unbind('click');

            return false;
          }

          counter++;
          return true;
        }
        
        
        
// Add form

$(".add-another-form").click(function(){

     if (checkCounter()) {
    $(".add-another-form").bind("click", function(e) {
     $(e.target).closest(".add-form").css("display", "block");
        });
           counter++;
        }

});

.add-form {
  display: none;
}

I have tried a few different way, but I could not be able make it work as expected. Any helps would be really appreciated.
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 9 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros