Javascript和JSP问题 [英] Javascript and JSP issue
问题描述
大家好我需要一些我正在尝试创建的Web应用程序的帮助,它是一个简单的JSP页面,您可以在其中插入,删除或更新存储在数据库中的表中的行。但是,我需要使用Java Script在将字段发送到服务器之前验证字段。这是JSP代码:
<%@ page contentType =text / htmlpageEncoding =UTF-8%>
<!DOCTYPE html>
< html>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = UTF-8>
< title>新记录< / title>
< / head>
< body>
< script type =text / javascript>
function validate(){
alert(你的数据即将被验证!);
//验证数据
返回false;
< / script>
< h1>新记录< / h1>
< form name =frmInNewaction =NewWSönsubmit=validate()method =POST>
在
< p>字段中输入数据
数字< input type =textname =txtNumbervalue =size =20/>
< p>
姓氏< input type =textname =txtLNvalue =size =20/>
< p>
中间名:< input type =textname =txtMNvalue =size =20/>
< p>
名称< input type =textname =txtNvalue =size =20/>
< p>
出生日期< input type =textname =txtBDvalue =size =20/>
< p>
薪水:< input type =textname =txtSalaryvalue =size =20/>
< p>
< input type =submitvalue =发送name =btnSend/>
< / form>
< / body>
< / html>
问题本身不是验证,问题是我甚至无法正确调用函数,因为你可以看到我发出警告来测试函数是否被正确调用但警报没有弹出。
我找不到我做错了什么,因为你可以看到我很新JS所以我希望你能帮我解决这个问题。谢谢
我能看到的问题
1. [由Sergey Alexandrovich Kryukov报道] - >那是onsubmit
,而不是önsubmit
。
2当你从函数返回boolean
值时,你应该在下面的调用中写一个return
语句(良好实践) )。
onsubmit =return validate();
3.在函数中缺少关闭花括号。
function validate(){
alert ( 您的数据即将被验证!);
// 验证数据
return false ;
} // 缺少这个。
建议
在FireFox
中查看FireBug
的控制台窗口,并检查是否还有其他错误
Hello guys I need some help with a web application I'm trying to create, it is a simple JSP page where you can insert, delete or update rows in a table stored in a data base. However, I need to use Java Script to validate the fields before sending them to the server. Here is the JSP code:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>New Record</title>
</head>
<body>
<script type="text/javascript">
function validate(){
alert("Your data is about to be validate!");
//validate data
return false;
</script>
<h1>New Record</h1>
<form name="frmInNew" action="NewWS" önsubmit="validate()" method="POST">
Enter data in the fields
<p>
Number <input type="text" name="txtNumber" value="" size="20" />
<p>
Last Name <input type="text" name="txtLN" value="" size ="20"/>
<p>
Middle Name: <input type="text" name="txtMN" value="" size="20" />
<p>
Name <input type="text" name="txtN" value="" size="20" />
<p>
Birth date <input type="text" name="txtBD" value="" size="20" />
<p>
Salary: <input type="text" name="txtSalary" value="" size="20" />
<p>
<input type="submit" value="Send" name="btnSend"/>
</form>
</body>
</html>
The issue is not the validation itself, the issue is I cannot even call the function correctly, as you can see I put an alert to test if the function was being called correctly but the alert does not pop up.
I cannot find what I'm doing wrong, as you can see I'm very new in JS so I hope you can help me on this one. Thanks
Issues I Can See
1. [As reported by Sergey Alexandrovich Kryukov] -> that isonsubmit
, notönsubmit
.
2. As you are returningboolean
value from function, you should write areturn
statement in the call like below (good practice).
onsubmit="return validate();"
3. Missing closing curly braces in the function.
function validate(){ alert("Your data is about to be validate!"); //validate data return false; } // This is missing.
Suggestion
See the console window ofFireBug
inFireFox
and check if you have any other errors.
这篇关于Javascript和JSP问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!