简体   繁体   English

HTML表单属性“名称”未在Firefox中定义

[英]HTML form attribute “name” not getting defined in Firefox

Below is the sample code in my JSP page: 以下是我的JSP页面中的示例代码:

<form name = loginform method = post action="">
<table class=registerTable>
<tr>         
    <td>Username:</td></tr>
    <tr><td>
    <input name=user type=text class=usnm required size=28 maxlength=35 autocomplete="off" onblur="validateUser()" onkeyup="checkUsernameAvailability(this.value)"><br></td></tr>
    <tr><td>
    <span id = uerrmsg class = error></span><br></td></tr>
</table>
</form>

When onblur=validateUser() is called the following code executes: 调用onblur=validateUser() ,将执行以下代码:

function validateUser(){
if(loginform.user.value.length<5){
    document.getElementById("uerrmsg").innerHTML="minimum 5 characters";
    return false;
}else{
    document.getElementById("uerrmsg").innerHTML="";
    return true;
    }
}

Error Console in FF gives the following error FF中的错误控制台给出以下错误

loginform is not defined 未定义loginform

Please help me on this. 请帮我。

PS: Above code works in all other browser. PS:以上代码可在所有其他浏览器中使用。

you can use input.getAttribute("name") to get name attribute of an input. 您可以使用input.getAttribute(“ name”)来获取输入的名称属性。 This works for almost all browsers. 这几乎适用于所有浏览器。

By the way, if you use getElementById, you must populate "id" field of input. 顺便说一句,如果使用getElementById,则必须填充输入的“ id”字段。

您应该使用document.loginform

You don't need the form for this. 您不需要此表格。 First give your input an id: id="user". 首先给您的输入一个id:id =“ user”。 Then you can access it using document.getElementById(), as you do with the element. 然后,可以像处理元素一样使用document.getElementById()访问它。 something like this: 像这样的东西:

document.getElementById("user").value.length

Also, your code is very non-standard, for eg you should not put a " " (space) between the attribute (or it's value) and the = sign. 另外,您的代码非常不规范,例如,您不应在属性(或其值)和=符号之间放置“”(空格)。 And the attributes' values should be within quotes (Look at the source code of this page, for example). 并且属性的值应在引号内(例如,查看此页面的源代码)。

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

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