0

I have the following form:

<form onsubmit="return testform(tolowanswers,emptyAnswers);" class="edit_question" id="edit_question" 

I check the Form before submit with the function testform, Is there a possibility to run a second function after testform()

thanks

5
  • what do you want to do in the new method Commented Aug 14, 2015 at 5:31
  • yes it is possible can you post your code Commented Aug 14, 2015 at 5:32
  • 2
    return testform(tolowanswers,emptyAnswers) && secondmethod(); Commented Aug 14, 2015 at 5:32
  • 1
    possible duplicate of How to call two functions on a form submit Commented Aug 14, 2015 at 5:37
  • @ArunPJohny thanks. will you post your comment as answer so I can mark It as solution? Commented Aug 14, 2015 at 5:52

2 Answers 2

1

One easy solution could to call the function like

return testform(tolowanswers,emptyAnswers) && secondmethod(); 

this will call the second function if testform returns true.

Another solution could to use another function like

onsubmit="return myfunction();" 

then

function myfunction() { if (testfunction()) { secondfunction(); } else { return false; } } 
Sign up to request clarification or add additional context in comments.

Comments

1

You just have to put those two functions inside the onsubmit event itself like below

"return (testform(tolowanswers,emptyAnswers) && secondFn())" 

It will check if the first function is true and only if it returns true, then the secondFn will be executed.

Another way would be to invoke secondFn() inside testForm function after all validation.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.