javascript function in jsp page

痞子三分冷 提交于 2019-12-08 08:09:58

问题


I have jsp page -

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
</head>
<body>

    <legend>Create new customer</legend>
    <script Language="JavaScript">
        function checkForm() {

            alert("YOU ARE IN checkForm FUNCTION !");
            return (false);
        }
    </script>
    <form action="CreateCustomerServlet" method="GET" onsubmit="checkForm">
        // form fields ... 
        <input type="submit" value="Create customer" />
    </form>
</body>
</html>

When I run on server this page and press on the submit button I see that it ignore checkForm and don't enter him , and directly go to CreateCustomerServlet .

My goals is that when press on submit it go to checkForm and if checkForm returns true only then it will go to CreateCustomerServlet . what I have to change in order to get this goal ?


回答1:


Try

onsubmit="return checkForm();"



回答2:


You should replace

onsubmit="checkForm"

By

onsubmit="return checkForm();"



回答3:


You should use

onsubmit="return checkForm();"

because only when false is returned from onSubmit will it be stopped , or else it will continue submitting the form.



来源:https://stackoverflow.com/questions/11792682/javascript-function-in-jsp-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!