Javascript和JSP问题 [英] Javascript and JSP issue

查看:60
本文介绍了Javascript和JSP问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我需要一些我正在尝试创建的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 is onsubmit, not önsubmit.

2. As you are returning boolean value from function, you should write a return 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 of FireBug in FireFox and check if you have any other errors.


这篇关于Javascript和JSP问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆