Mewster
Mewster

Reputation: 1063

Avoid unwanted form submission

I have a problem when I want to use a button to switch into another page, and another button to just close the window (a popup)

No matter which button I click, the form submits. What can I do to avoid this (apart from switching the </form> between the two buttons) ?

The code:

<form action="name.php" method="post">
                <input type="hidden" name="number" value="<?php echo $id;?>">
                <input type="hidden" name="position" value="<?php echo $pos;?>">
<button type="submit">Yes</button> <button onclick="window.close()">No</button>
</form> 

Upvotes: 1

Views: 408

Answers (1)

Tuanderful
Tuanderful

Reputation: 1319

You can add return false to the end of the onclick for your second button:

<button onclick="window.close(); return false">

Upvotes: 5

Related Questions