0

I am trying to process a form using Jquery and when Javascript is not available (or turned off) in the browser then it should be processed using PHP.

To do this, I've added action='php_file' and onsubmit='myFunction();' to the form tag.

What it should do:

  • When JS is available: alert("Success!");
  • When JS not available: post data to getdata.php

But when I click on the submit button, the page goes to the PHP file after showing alert box.

You can see the page at http://cgpacalculator.in/

Edit: Here's the form code

<script>
function myFunction(){
        alert("Success!");
}
</script>
<form method="post" action="getdata.php" id="calculator" onsubmit="myFunction();">
 <!-- table here -->
 <input class="myButton" type="submit" value="Calculate">
 </form>

Any idea?

Thanks in advance :)

NoobBoy
  • 1
  • 2

1 Answers1

1
function myFunction() {
  ....
 return false; //stop default behaviour

}
Julian
  • 781
  • 1
  • 11
  • 32
  • You could return what ever you want from `myFunction` and it would not change anything, because the code of the OP is `onsubmit='myFunction();` and not `onsubmit='return myFunction();`, and it is not only `//stop default behaviour` but also stops propagation. – t.niese May 18 '16 at 15:41