最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - <button type="submit"> with onclick submitting twice? - Stack Overflow

programmeradmin1浏览0评论

I am currently facing some order duplication issues. Without going into too much detail, I had a question about the following. Is there any possibility that this can trigger a submit twice?

<button type="submit" onclick="review.save()"></button>

review.save() will handle the submission of the form - so in fact the type=submit isn't needed here. But I want to establish whether this CAN cause the browser to submit twice. On the server logs the 2 submits were about 10 seconds apart.

I am currently facing some order duplication issues. Without going into too much detail, I had a question about the following. Is there any possibility that this can trigger a submit twice?

<button type="submit" onclick="review.save()"></button>

review.save() will handle the submission of the form - so in fact the type=submit isn't needed here. But I want to establish whether this CAN cause the browser to submit twice. On the server logs the 2 submits were about 10 seconds apart.

Share Improve this question asked Nov 5, 2013 at 12:34 Francis KimFrancis Kim 4,2954 gold badges38 silver badges51 bronze badges 2
  • The browser does not submit twiche. It submits, when the button is clicked. What your function call review.save() does is on another page... ;) – I'm with Monica Commented Nov 5, 2013 at 12:37
  • Impatient users clicking twice maybe? Its a good idea to disable the button so as the users cannot click twice. – Fred Commented Nov 5, 2013 at 12:37
Add a ment  | 

2 Answers 2

Reset to default 5

You need to prevent default browser behaviour, for example:

<button type="submit" onclick="review.save(); return false;"></button>

Add a return false to your Button or better the 'oncklick' event!

Like:

<button type="submit" onclick="review.save();return false;"></button>

It "stops" the default browser behaviour of following links (in that case).

Edit: To slow :/

发布评论

评论列表(0)

  1. 暂无评论