about click and submit
example below:
<form action="url" method="post">
<input type="text" id="input1"/>
<input type="submit" value="submit" onclick="testFun()"/>
</form>
if it is possible that function testFun run after the form’s submit when we click the button to submit
if the answser is no.
why? how does the browser work when click the submit button?? the order is click function-> submit ? is right??
No you cannot execute a function after the form has been submitted – the order of which things are executed is as follows :
onclickfunction is executedurlspecified in the action of the formYou can prevent the browser submitting the page by returning
falsefrom the onclick handler :the submit button should then be modified like this :
If you do wish to execute a function after the form has been submitted you need to submit the form using AJAX – this doesnt cause the browser to navigate away from the page and a JavaScript function can be executed after the form has been submitted