1

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> 
1
  • I would not use a <button> tag to close the window. Use anchor link and javascript. This would be more semantically appropriate. Commented Dec 28, 2012 at 12:09

1 Answer 1

5

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.