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 of submit. 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
Add a ment  | 

5 Answers 5

Reset to default 5

change

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