0

In js, I need to use :

$('.grid').on('submit','form', function (ev) {}

because i need to validate a html5 element into the form.

My problem is:

I have 2 submit button with 2 kind of "data". I need to get the trigger for using:

 if(typeof [trigger].data('save') != 'undefined'){
 }

it is the part of my current JS:

$('.grid').on('submit','form', function (ev) {
ev.preventDefault();
console.log(typeof $(this).data('save') );
if(typeof $(this).data('save') != 'undefined' && jQuery("form")[0].checkValidity()){
 // do something
 }
});

$(this) refere to the form element. I need that find the submit triggered button (not twice and not other submit button)

thanks

asked Apr 23, 2014 at 12:55
1
  • Have you tried $(ev.target).data('save')? Commented Apr 23, 2014 at 12:57

1 Answer 1

3

You should use event.target

The DOM element that initiated the event.

Change code to

 if(typeof $(ev.target).data('save') != 'undefined'){
 }
answered Apr 23, 2014 at 12:59
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.