Jump to content

Submit button doesn't run the action if javascript fails


Mudsaf

Recommended Posts

I'm wondering is it possible to make javascript that doesn't let the user go to example action="test.php" page if javascript says so. Example im having this javascript

<script type="text/javascript">var r=confirm("Click the OK button now!");if (r==true){  alert("You pressed OK!");<!-- THIS SHOULD ALLOW THE ACTION (SO IT WOULD ALLOW USER TO CONTINUE TO ACTION PHP PAGE) -->}else{  alert("You pressed Cancel!");<!-- THIS SHOULD CANCEL THE ACTION (SO IT WOULD NOT CONTINUE TO ACTION PHP PAGE) -->}</script>

So if user presses OK it allows user get to the next page and if user press cancel it doesn't let Oo found cool page with info at this http://www.htmlforums.com/client-side-scripting/t-how-to-cancel-submit-action-33810.html

Edited by Mudsaf
  • Like 1
Link to comment
Share on other sites

Here is the code if it helps anyone (Works like charm)

<script type="text/javascript">function conf_delete() {var r=confirm("Click the OK button now!");if (r==true){  alert("You pressed OK!");return true; }else{  alert("You pressed Cancel!");return false;}}</script></head><body><form id="form1" onsubmit="return conf_delete()" name="form1" method="post" action="#">  <label>    <input type="submit" name="submit" id="submit" value="Submit" />  </label></form>

Link to comment
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
×
×
  • Create New...