1

I'm stuck with 2 forms on a single bootstrap page that don't don't seem to validate. Each form is using a different validation but since I'm not pointing out to any specific form ID in my .js files, the first .js file is applied to each form. I'm struggling go get each .js validation file to apply to the correct form.

On my index.html page, I have something like:

<form name="sentMessage" id="contactForm" novalidate>
...
<form name="sentOrder" id="orderForm" novalidate>
...
<script src="js/jqBootstrapValidation.js"></script>
<script src="js/contact.js"></script>
<script src="js/order.js"></script>

Each .js file looks like:

$(function() {

$("input,textarea").jqBootstrapValidation({
    preventSubmit: true,
    submitError: function($form, event, errors) {
        // additional error messages or events
    },
    submitSuccess: function($form, event) {
        event.preventDefault(); // prevent default submit behaviour
        // get values from FORM
        var nameSender = $("input#orderNameSender").val();

If I try $("#orderForm").(function() and $("#contactForm")(function() it doesn't work. Thanks in advance for your help!

2
  • Try using some class $(".testStack").jqBootstrapValidation({ <form name="sentOrder" id="orderForm" class="testStack" novalidate> Commented Feb 4, 2015 at 1:40
  • Thank you, Ethaan, but that didn't work either. Behaviour without adding anything submits the form but always uses the first .js file called. Adding the class or the id prevents from submitting the form and clicking the submit button also makes the focus go back to the top of the page. Commented Feb 4, 2015 at 1:48

1 Answer 1

2

.find might work.

$(function(){
        $("#contactForm").find('textarea,input').jqBootstrapValidation({
             //jqBootstrapValidation CODE
        });
    });
Sign up to request clarification or add additional context in comments.

1 Comment

Fantastic, that worked. Thank you for your help, really appreciative of your precise and quick answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.