I have a single input form:
<form id="my_form">
<input id="my_input" type="text" />
</form>
In most browsers, when a user types text in this single input and hits 'enter' the form is submitted. That's great but I want to go one step further and make it so that if the user types something and focus is lost, the form is submitted.
I've currently tapped into jQuery's change event like so:
$("my_input").change(function() {
$("my_form").submit();
});
This works for the case when I change the input value and focus out but if I change the input value and hit 'enter' then the form is submitted twice (once for 'enter' and once for change).
I was starting to go down the path of lower level listening to keys and managing a submit state but figured I'd throw it out to the community to see if anyone knows of a cleaner way.