Dhawal Mhatre
Dhawal Mhatre

Reputation: 435

HTML 5 Validation on button Click

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?

Upvotes: 1

Views: 6273

Answers (2)

Adesh M
Adesh M

Reputation: 444

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

Upvotes: 0

Dhawal Mhatre
Dhawal Mhatre

Reputation: 435

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;
    }
   });

Upvotes: 1

Related Questions