1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

two forms javascript checkbox conflict

Discussion in 'JavaScript' started by Ian Haney, Jul 16, 2019.

  1. #1
    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

    <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

    <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
     
    Ian Haney, Jul 16, 2019 IP
  2. Ian Haney

    Ian Haney Banned

    Messages:
    131
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    78
    #2
    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
     
    Ian Haney, Jul 16, 2019 IP