admin管理员组文章数量:1279207
I have a problem on html button tag
This my html code
<form name="data_kirim" action="confirm_order.php" method="POST">
..... order input field ....
<button class="back_button" onclick="window.location.href='keranjang.php'">Back</button>
<input class="next_button" type="submit" name="submit_data_kirim" value="Next"/>
</form>
How to prevent button to submit this form, because button is using the href to back page,
Can someone help me?
I have a problem on html button tag
This my html code
<form name="data_kirim" action="confirm_order.php" method="POST">
..... order input field ....
<button class="back_button" onclick="window.location.href='keranjang.php'">Back</button>
<input class="next_button" type="submit" name="submit_data_kirim" value="Next"/>
</form>
How to prevent button to submit this form, because button is using the href to back page,
Can someone help me?
Share Improve this question edited Dec 24, 2013 at 5:30 MysticMagicϡ 28.8k16 gold badges75 silver badges125 bronze badges asked Dec 24, 2013 at 4:30 HansenHansen 6902 gold badges13 silver badges35 bronze badges 2-
Make the type as
button
instead ofsubmit
. Call a JS function to do what you need to. – Aashray Commented Dec 24, 2013 at 4:37 - developer.mozilla/en-US/docs/Web/API/event.preventDefault – Aldi Unanto Commented Dec 24, 2013 at 4:39
5 Answers
Reset to default 5change
type='submit'
to
type='button'
<button class="back_button" onclick="window.location.href='keranjang.php'">Back</button>
<form name="data_kirim" action="confirm_order.php" method="POST">
<input class="next_button" type="submit" name="submit_data_kirim" value="Next"/>
</form>
A quick solution would be to move the back button outside the form since It's not using the form inputs anyway.
you can call a function in javascript when click your button, redirect to your link and return false
or use preventDefault()
function with jquery
<form onsubmit="return false;">
If you want to just make it link to another page and not submit the form then simply make it a normal button like so :
<a href="URL">Next</a>
This will not submit the form though.
本文标签: javascriptprevent button submit form onclickStack Overflow
版权声明:本文标题:javascript - prevent button submit form onclick - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741273505a2369596.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论