登录页面 - onsubmit函数调用问题 [英] Login Page - onsubmit function call problem

查看:124
本文介绍了登录页面 - onsubmit函数调用问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是登录页面的代码。但是,我似乎无法通过onsubmit来调用该函数。我也尝试过提交onclick选项。不用说,这也不起作用。



有谁能告诉我哪里出错了?

The following is a code for a login page. however, I cant seem to get the "onsubmit" to call the function. I've also tried the "onclick" option with submit. Needless to say that that doesn't work either.

Could anyone tell me where am I going wrong?

<html>
<head>
<title>Login Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function checkinput(form){
    if ((form.LoginId.value===null)||(form.LoginId.value.trim().equals(""))){
        alert('Please enter LoginId');
        form.LoginId.focus();
        return false;
    }
    if ((form.password.value===null)||(form.password.value.trim().equals(""))){
        alert('Please enter Password');
        form.password.focus();
        return false;
    }
}
</script>    
</head>
<body>
    <h1 align="center">Please Enter your Login Credentials</h1>
    <form action="LoginValidator" method="post" name="login"  önsubmit="return checkinput(this);">
        LoginId <input type="text" name="LoginId" maxlength="10"><br /><p>
        LoginRole <select name="LoginRole" size="1">
            <option value="consumer">Consumer</option>
            <option value="administrator" selected>Administrator</option>
            <option value="manager">Manager</option>
            <option value="publicreviewer">Public Reviewer</option>
        </select><br/><p>
        Password <input type="password" name="password" maxlength="20"><br/><p>
        <input type="submit" > <input type="reset">
    </form>
<body>
</html>

推荐答案

查看 [ ^ ]文章。





- Amit


Hello Tanmoy,



这是checkinput功能中的问题。请更正如下所示。

Hello Tanmoy,

It's the problem in your checkinput function. Please correct it as shown below.
function checkinput(form){
    var fval = form.LoginId.value;
    if (fval===null || fval === "" || "".equals(fval)){
        alert('Please enter LoginId');
        form.LoginId.focus();
        return false;
    }
    fval = form.password.value;
    if (fval===null || fval === "" || "".equals(fval)){
        alert('Please enter Password');
        form.password.focus();
        return false;
    }
}



我还发现您错误地发布的代码名称 onsubmit 方法为önsubmit(注意字母o顶部的两个小点)。还请正确关闭输入按钮标签。可以在这里找到测试平台[ ^ 在JSFiddle上。



问候,


I also observed that the code you have posted wrongly names onsubmit method as önsubmit (Notice two small dots on top of letter o). Also please properly close the input button tags. The testbed can be found here[^] on JSFiddle.

Regards,


这篇关于登录页面 - onsubmit函数调用问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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