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?
By using HTML Anchor Tags <a>.. </a>, you can Redirect on a SIngle Button Click [html button click redirect]. To use HTML Anchor tags to redirect your User to Another page, you need to write your HTML Button between these HTML Anchor Tag's starting <a> and Closing </a> Tags.
Using button tag inside <a> tag: This method create a button inside anchor tag. The anchor tag redirect the web page into the given location. Adding styles as button to a link: This method create a simple anchor tag link and then apply some CSS property to makes it like a button.
On any Windows Form, you can designate a Button control to be the cancel button. A cancel button is clicked whenever the user presses the ESC key, regardless of which other control on the form has the focus.
cancel
is not a valid value for a type attribute, so the button is probably defaulting to submit
and continuing to submit the form. You probably mean type="button"
.
(The javascript:
should be removed though, while it doesn't do any harm, it is an entirely useless label)
You don't have any button-like functionality though, so would be better off with:
<a href="http://stackoverflow.com"> Cancel </a>
… possibly with some CSS to make it look like a button.
There is no button type="cancel"
in html. You can try like this
<a href="http://www.url.com/yourpage.php">Cancel</a>
You can make it look like a button by using CSS style properties.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With