With form validation: why onsubmit=“return functionname()” instead of onsubmit=“functionname()”?

后端 未结 6 2127

The question is pretty self-explanatory. I don\'t understand what the return is doing in the following code:

6条回答
  •  伪装坚强ぢ
    2020-12-02 13:47

    Returning false from the function will stop the event continuing. I.e. it will stop the form submitting.

    i.e.

    function someFunction()
    {
        if (allow) // For example, checking that a field isn't empty
        {
           return true; // Allow the form to submit
        }
        else
        {
           return false; // Stop the form submitting
        }
    }
    

提交回复
热议问题