0

I have this code http://jsfiddle.net/2Gay9/3/

HTML

<form action="/" method="get" onsubmit="return false";> test: <input type="text" value=""> <input type="submit" value="submit"> </form> 

JS

jQuery('input').bind("keydown click", function(event){ console.log(event.type); console.log(jQuery(this)); }); 

Try hit RETURN in input text and look console:

keydown jQuery(input) click jQuery(input submit) 

QUESTION: Why browser is triggering a 'click' event on submit button, instead of trigger a 'submit' event in the form? Is this a project flaw or a specification? How can I cancel second event WITHOUT cancel form submission?

Tks

UPDATE In other words, I just need to diferenciate my event from browser event.

1

2 Answers 2

0

use:

jQuery('input').bind("keydown click", function(event){ event.preventDefault(); console.log(event.type); console.log(jQuery(this)); }); 
Sign up to request clarification or add additional context in comments.

3 Comments

I dont want do stop form submission because I have a lot of js that depends on this. I want just to diferenciate my event from browser event.
you mean custom events/event delegation?
No. I just want to know if a user clicked in submit button or if this click was triggered by browser.
0

SOLVED!

If I cant stop click event on submit button, I can workarround only diferenciating browser from users click. To diferenciate browsers click from users click I will use mousedown event instead of click event.

Every time we hit RETURN in a input text, browser trigger click on first submit button in current form. But this don't trigger mousedown event, "exclusive for humans" in this case.

Fixed version, that prints event once.

jQuery('input').bind("keydown mousedown", function(event){ console.log(event.type); console.log(jQuery(this)); }); 

http://jsfiddle.net/2Gay9/6/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.