Results 1 to 2 of 2

Thread: two forms javascript checkbox conflict

  1. #1
    Join Date
    May 2012
    Posts
    216
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default two forms javascript checkbox conflict

    I have two contact forms, one is in includes/footer.php and one on contact.php and when on the contact page, if I try to submit the form in the footer, it won't submit because I got checkbox validation on each form that the user has to agree to the terms before the form submits so tried the following but either form still don't submit unless both checkboxes are checked

    the form checkbox code in the footer.php is below

    Code:
    <div class="col-md-12 mb-3">
                                        <input type="checkbox" id="agreefooter" /> I have read and agree to MM PC Solutions <a href="privacy-policy.php" target="_blank">Privacy Policy</a>
                                        </div>
    
    <script>
                                    $(".needs-validation").submit(function(e){
           if(!$("#agreefooter").is(":checked")){
                alert('Please indicate that you have read MM PC Solutions Privacy Policy');
                e.preventDefault();
           }
        });
                                    </script>
    The form checkbox code on the contact page is below

    Code:
    <div class="col-md-12 mb-3">
                                        <input type="checkbox" id="agreecontact" /> I have read and agree to MM PC Solutions <a href="privacy-policy.php" target="_blank">Privacy Policy</a>
                                        </div>
    
    <script>
                                    $(".needs-validation contactform").submit(function(e){
           if(!$("#agreecontact").is(":checked")){
                alert('Please indicate that you have read MM PC Solutions Privacy Policy');
                e.preventDefault();
           }
        });
                                    </script>
    Can anyone help please so the forms don't conflict and allows to me submit the form if either form does not have the checkbox in their form checked

    Hope that makes sense

  2. #2
    Join Date
    May 2012
    Posts
    216
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    I have managed to solve the issue now with similar coding but put onsubmit in the form tag itself and changed the id in the onsubmit code and the checkbox id code

Similar Threads

  1. Please help with checkbox Javascript function
    By deziner76hd in forum JavaScript
    Replies: 3
    Last Post: 05-06-2012, 04:30 PM
  2. Javascript with Checkbox on Forms.
    By Brooksy in forum JavaScript
    Replies: 3
    Last Post: 08-04-2010, 12:45 AM
  3. Checkbox value in forms
    By lord_havoc in forum HTML
    Replies: 1
    Last Post: 11-02-2007, 02:43 AM
  4. Having Problems With Javascript (Checkbox)
    By screamo in forum JavaScript
    Replies: 0
    Last Post: 03-20-2007, 04:58 AM
  5. javascript checkbox validation
    By picaso in forum JavaScript
    Replies: 1
    Last Post: 09-21-2006, 03:08 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •