Hansen
Hansen

Reputation: 690

prevent button submit form onclick

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?

Upvotes: 2

Views: 6178

Answers (5)

Mahfud Harun
Mahfud Harun

Reputation: 947

you can call a function in javascript when click your button, redirect to your link and return false or use preventDefault() function with jquery

Upvotes: 2

Anshu Dwibhashi
Anshu Dwibhashi

Reputation: 4675

<form onsubmit="return false;">

Upvotes: 1

Rami Sakr
Rami Sakr

Reputation: 372

<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.

Upvotes: 2

hsuk
hsuk

Reputation: 6860

change

type='submit'

to

type='button'

Upvotes: 5

ProEvilz
ProEvilz

Reputation: 5455

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.

Upvotes: 0

Related Questions