Jump to content
Sign in to follow this  
The Praetorian

Cancel button for forms?

Recommended Posts

Is there a button for forms to cancel? ( Ie, type="cancel" ) that will send the person back one page?
Nope. If you want to have a cancel button, you have to make it yourself.

Share this post


Link to post
Share on other sites

JavaScript prompt does this, but I don't know how to get it into the form..But if you can use PHP:

<?phpif (isset($_POST['cancel'])) {header('Location: back_to_the_previous_site.php');die('');}?><form action="" method="post"><input type="submit" name="submit" value="Submit" /><input type="submit" name="cancel" value="Cancel" /></form>

***The PHP-code must be over the doctype and it only works if you can use PHP!

Share this post


Link to post
Share on other sites

in JavaScript you could do this

<input type="button" value="Cancel" onclick="history.back()"/>

Share this post


Link to post
Share on other sites

oooor:

<input type="button" value="Cancel" onclick="history.go(-1)"/>

hehe

Share this post


Link to post
Share on other sites

or

<input type="button" value="Cancel" onclick="window.location='url to any page you want'"/>

:)

Share this post


Link to post
Share on other sites

or

<input type="submit" value="Cancel" onclick="this.form.onsubmit=function() { history.back(); return false; }" />

:)

Share this post


Link to post
Share on other sites
or
<input type="submit" value="Cancel" onclick="this.form.onsubmit=function() { history.back(); return false; }" />

:)

I have no response to this *shakes head in disbelief*As crazy as that is it would work, not exactly best practice though

Share this post


Link to post
Share on other sites

or

<input type="button" value="Cancel" onclick="alert('Action Cancel.\nClick OK to continue.'); window.location='yourpage.htm'"/>

:)

Share this post


Link to post
Share on other sites
I have no response to this *shakes head in disbelief*As crazy as that is it would work, not exactly best practice though
Hah! I tried to get even more elaborate but it turns out there are security issues with accessing the history objects properties. Oh well.How about:
<input type="button" value="Cancel" onclick="if(confirm('Are you SURE you wish to cancel?')) history.back();" />

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×