I am playing with the Buttons in the w3schools Tryit editor, and I am trying to figure out how to make my browser redirect to an URL when I click on the "Cancel" button.
Here's what I have tried:
<form action="demo_form.asp" method="get">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<button type="submit" value="Submit">Submit</button>
<button type="reset" value="Reset">Reset</button>
<button type="cancel" onclick="javascript:window.location='http://stackoverflow.com';">Cancel</button>
</form>
But it doesn't work. Any ideas?
Just put type="button"
Because your button is inside a form it is taking default value as submit and type="cancel" doesn't exist.
Not enough rep to Vote Up for Kostyan. Here's my final solution (needed a reset button).
Thanks again to Kostyan for answering the question as asked without suggesting a "workaround" (time-consuming) method to "construct a button" with styles.
This is a Button (which the viewer expects to see) and it works exactly as requested. And it mingles with the other buttons on the page. Without complexity.
I did remove the "type=cancel" which apparently was useless. So even less code. :)
With Jquery:
Here, i am using link in the form of button for CANCEL operation.
it defaults to submitting a form, easiest way is to add "return false"