JavaScript code to stop form submission

前端 未结 12 2093
感情败类
感情败类 2020-11-21 06:40

One way to stop form submission is to return false from your JavaScript function.

When the submit button is clicked, a validation function is called. I have a case i

12条回答
  •  北荒
    北荒 (楼主)
    2020-11-21 06:48

    You can use the return value of the function to prevent the form submission

    and function like

    
    

    In case of Chrome 27.0.1453.116 m if above code does not work, please set the event handler's parameter's returnValue field to false to get it to work.

    Thanks Sam for sharing information.

    EDIT :

    Thanks to Vikram for his workaround for if validateMyForm() returns false:

     
    

    where validateMyForm() is a function that returns false if validation fails. The key point is to use the name event. We cannot use for e.g. e.preventDefault()

提交回复
热议问题