Jump to content
Sign in to follow this  
Mudsaf

Submit button doesn't run the action if javascript fails

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

Share this post


Link to post
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>

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...