1

I have the below form:

<form>
  <input type="name" required/>
  <input type="button" value="Send"/>
 </form>

The above form is in Bootstrap Modal Box On Send button; I want to change the HTML 5 required validation.

I don't want the button type to be submitted. As page gets refreshed and the modal box is closed down ??

What can I do to validate HTML 5 without clicking on sumbit button?

5
  • The HTML5 form validation is meant to take place on submit. If you want a validation that could be triggered at whatever point (which does not make sense to me, because that could disturb a use while filling the form) you have to use a good ol' JS form validator. Ask yourself at first, “why would you validate some form input, if you don't want to submit it?” Commented Oct 5, 2015 at 12:16
  • @Dhawal - You can achieve it by various means; see my JS Fiddle below. Commented Oct 5, 2015 at 13:56
  • @feela This misunderstands the meaning of forms, validations, and submission. There are plenty of ways to use HTML5 form validation outside of a classic form workflow. There's an entire API designed to support doing that. Commented Oct 5, 2015 at 14:22
  • 1
    Possible duplicate of How to force a html5 form validation without submitting it via jQuery Commented Oct 5, 2015 at 14:25
  • thanks torazaburo... i have used same script as you have given in the above link.. Commented Oct 6, 2015 at 11:33

2 Answers 2

1

Thanks all for your replies..

I have done it successfully... with below script

  $('button.saveChange').click(function(){
    if (!$('#vehicleForm')[0].checkValidity()) {
        $('#vehicleForm').find('input[type="submit"]').click();
        return false;
    }
   });
Sign up to request clarification or add additional context in comments.

1 Comment

hello, i have used the gone through above link which you provided, it has same solutions and its working properly as i need..
0

You can use e.preventDefault() to override default form action instead of using return false. Can be used with combination of form event submit (or button event click)

e.preventDefault();

See My JS Fiddle

Comments

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.