and function in onsubmitbelow: f...">

Form submission

I have this form:

<form id="basicTerms" method="post" onsubmit="return validateForm()">

and function in onsubmitbelow:

function validateForm()
{
    return false;
}

I did this to check the form, and when I press "Enter" or press the button on the form that executes the triggers, the form submit action, the form is submitted and goes to the next page.

I also have these buttons in the form:

<tr>
    <td align="left"><button style="background-color:#FF80FF" onclick="javascript:document.getElementById('basicTerms').action='helpFile1.php'; document.getElementById('basicTerms').submit()" tabindex="6">Go Back</button></td>
    <td align="center"><button style="background-color:#FFC080" onclick="javascript:document.getElementById('basicTerms').action='helpFile2.php'; document.getElementById('basicTerms').submit()" tabindex="4">Lets Go To Step 2</button></td5>
    <td align="right"><button style="background-color:#00FF00" onclick="printThis()" tabindex="5">Print</button></td>
</tr>

I want to know why forms are submitted even when I return false in onsubmit.

I tested the form in Google Chrome and FireFox, both gave the same result. In addition, I am testing on localhost WAMP: Apache2.2.11, PHP5.3.0.

+3
source share
2 answers

Try adding type="button"buttons to your tags. Otherwise, I believe that they represent buttons by default.

( , )

+4

form.submit() -, validateForm() .

+2

Source: https://habr.com/ru/post/1783449/


All Articles