简体   繁体   English

尝试验证jsp表单时,外部js文件不起作用

[英]external js fiie not working when trying to validate a jsp form

the jsp page containing form包含表单的jsp页面

function formValidation()
{

    var fname= document.form1.first_nm;


<form name="form1" onsubmit="return formValidation()" method="post">

First Name:<input type="text" name="first_nm" /><br>

My jsp page:

index.jsp

The jsp page contains the form on using the onsubmit event it is not loadingthe extyernal js file. jsp 页面包含使用 onsubmit 事件的表单,它不加载外部 js 文件。 please help.请帮忙。 I am not able to get where I am going wrong.我无法找到我出错的地方。

<script type="text/javascript">
function FormCheck()
{
  var x = document.forms["form1"]["first_nm"].value;
  var y = document.forms["form1"]["last_nm"].value;
    if (x == null || x == "") {
        alert("FirstName must be filled out");
        return false;
    }
     if (y == null || y == "") {
        alert("LastName must be filled out");
        return false;
    }
}
</script>

I am Assuming that your Jsp page is Something like this我假设你的 Jsp 页面是这样的

<html:form action="form1" name="form1" onsubmit="return FormCheck();" method="POST">    

First Name:<input type="text" name="first_nm" /><br>
Last  Name:<input type="text" name="last_nm" /><br>
.
.
.

</html:form>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM