Reputation:
I have a form,if users clicks cancel with value or w/o value in the textfield it should redirect.
Now w/o entering value it is working.If users enters it is getting into db.
I tried all js scripts but still not working
Thanks in advance.
Upvotes: 1
Views: 31073
Reputation: 457
Why redirec? Should cancel work as canceling the actual action and getting back to previous one? I thing that history.back() should be suffcient in js. Or window.close() if the form is opened in new window. But to make this happend you should make cancel a regular button, not a submit.
Something like this:<input type="button" ... value="Cancel" onclick="history.back();" />
Upvotes: 6
Reputation: 31
Try this and change redirectpage to your redirectpage.
<input type="button" value="cancel" onClick="document.location.href='http://www.redirectpage.com';" />
Upvotes: 3
Reputation: 34107
You should emphasize the default (submit) action versus the secondary one (cancel). Make submit a regular submit button, cancel a link to the previous page.
Upvotes: 1
Reputation: 2468
whenever you have an <input type="submit">
think of this as just another field value you can check against in your code. e.g. try this:
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="GET">
<input type="submit" name="foo" value="submit">
<input type="submit" name="foo" value="cancel">
</form>
<?php
//validation removed..
if ($_GET['foo'] == 'submit')
{
//do snazzy stuff
print('submit pressed')
}
if ($_GET['foo']) == 'cancel')
{
//do snazzy stuff
print('cancel pressed')
}
?>
hope this helps?
Upvotes: 2