Submitting a form with the enter button in a form with several submit buttons

后端 未结 4 1382
南笙
南笙 2021-01-12 11:38

I have a form with a simple text field and multiple submit buttons. When the user presses enter, I want to submit the form with a specific submit button, but it looks like t

4条回答
  •  孤独总比滥情好
    2021-01-12 12:21

    You can use simple JS to catch the onkeypress event:

    onkeypress="if ((event.keyCode | event.which) == 13) { document.getElementById('MySubmitButton').click(); return false; }"
    

    Just add this to the textbox tag and replace "MySubmitButton" with the ID of the desired submit button.

    Note: use ID, not name.

提交回复
热议问题