1

Sorry if its question is reasked. I'm creating a form and asking user to confirm but its not working its always proceding whether user clicks ok, cancel or even close the confirm window. Here is the code:

FORM:

<form action="simple_things.php" class="right inline" method="POST" onsubmit="confirm_input();">
                    <input type="submit" class="btn red small" name="reset" value="Reset Points">
                    <input type="submit" class="btn red small" name="reset" value="Reset Referals"> 
                </form>

Script

<script type="text/javascript">
        function confirm_input() {
            var r = confirm("Do you really wanted to reset?");
            return r;
} </script>

2 Answers2

0

Thats because the type of both the buttons are submit. Use type submit only on the button that you want to confirm the submission.

Lakmal Caldera
  • 1,001
  • 2
  • 12
  • 25
  • I don't think so it's working now solution by Pravan C Balan. Problem was this: onsubmit="return confirm_input();" – Pranjal Saxena Nov 28 '15 at 09:27
  • Yes Pravan C Balan suggestion worked, but I meant if you want to the function to execute on the both the buttons, I suppose you could have type of submit on both the input button, but frankly that doesn't make sense. – Lakmal Caldera Nov 28 '15 at 09:40
0

Check out this and let me know if you are facing any error.

<form action="simple_things.php" class="right inline" method="POST" onSubmit="return confirm('confirm ?');">
  <input type="submit" class="btn red small" name="reset" value="Reset Points">
  <input type="submit" class="btn red small" name="reset" value="Reset Referals"> 
</form>
Prafulla Kumar Sahu
  • 9,321
  • 11
  • 68
  • 105
  • Yup it worked! But why we need two returns function was also returning true and false Any idea..? – Pranjal Saxena Nov 28 '15 at 09:29
  • Do you want to know why we need the confirm option ?? to alert if the user is going correct, so that he will think of rechecking it . – Prafulla Kumar Sahu Nov 28 '15 at 09:32
  • @PranjalSaxena Are you asking something else let me know. – Prafulla Kumar Sahu Nov 28 '15 at 09:39
  • I'm not a js developer but know confirms return true or false based on whether user clicks ok or cancel. But you see function i created is returning that value already "function confirm_input() { var r = confirm("Do you really wanted to reset?"); return r; } " and we are using a return again in onsubmit attribute? – Pranjal Saxena Nov 28 '15 at 09:42
  • @PranjalSaxena u do not need that function if you are using this code either use this or call that function when the user is submitting no need to use both .You can change the message for user, I have left it as only "confirm ?" . – Prafulla Kumar Sahu Nov 28 '15 at 09:45