I found this article (http://www.developertutorials.com/tutorials/javascript/javascript-form-submission-no-button-050412-1292/), but it is 8 years old (c. 96 in Internet and duckbilled Platypus years).

strager's answer here: Submitting a form by pressing enter without a submit button indicates that it might be as easy as calling "this.form.submit();" in a selection's event (onChanged() or whatever).

Is that so? Or not so? Or so not so?

有帮助吗?

解决方案

It's true. You can generally call submit() on a form on any event, as long as you identify the form clearly. @pXL uses jQuery syntax for that; my only caution is that you need to make certain there's only one form on the page, because jQuery fires the handler on the list of elements its selector returns. Either name the form

$('form[name=theOne]')

or use an Array accessor

$('form')[0]

You can make it fire on keyUp in a field (you could test the key value to match 'return'), or even if the user clicks somewhere outside the form.

$('html').click(function(){$('form')[0].submit()});

(This is probably not the best user experience, though!)

其他提示

Yes, you can submit the form using .submit() no need of submit button

Html :

<form action="some.php" method="get">
  First name: <input type="text" name="fname">
  Last name: <input type="text" name="lname">
</form>

JS:

$('form').submit();

Demo ---> http://jsfiddle.net/PqXWJ/19/

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top