what is the simplest way to auto-submit form when the user click out side the div?
Just consider the div not the form elements.
<div id="formDiv">
<form id="search">
<input id="target" type="text" value="Field 1" />
<input type="text" value="Field 2" />
</form>
</div>
You can add a
clickhandler todocumentthat isn’t activated inside the<div>, like this:What this does, is any click on
document, results in the<form id="search">being submitted, but from inside the<div>we stop thatclickevent from reaching (bubbling up to)documentviaevent.stopPropagation().If the
#searchform may be hidden at times and you only want this to kick in when it’s shown for example, no problem, just add a:visibleto the selector, like this: