Javascript函数无法正常工作。编辑

时间:2021-06-21 21:27:59

I've created a registration form for users to fill in their data and submit for registration. If some fields are empty, a user name is unavailable, or if that user's email is already registered, a warning appears below the submit button, halting their process until their errors are corrected.

我已经为用户创建了一个注册表,以填写他们的数据并提交注册。如果某些字段为空,用户名不可用,或者如果该用户的电子邮件已经注册,则会在提交按钮下方显示警告,暂停其过程,直到纠正错误为止。

Below the email and username input boxes, there is a span id called emailstatus and unamestatus, respectively. If the email or user name is already registered or unavailable, a message is placed within that span informing the user. However, whether the message is shown or not, even if there is nothing wrong with the user's information, the span id status always has the message "Please correct your errors." which can be found in the javascript function signup(). Please help.

在电子邮件和用户名输入框下方,分别有一个名为emailstatus和unamestatus的span id。如果电子邮件或用户名已注册或不可用,则会在该范围内放置一条消息,通知用户。但是,无论是否显示该消息,即使用户的信息没有任何问题,跨度ID状态也始终显示消息“请更正您的错误”。可以在javascript函数注册()中找到。请帮忙。

HTML:

<p>Enter personal details</p>
   //cleaned up code
    <input id="email" onfocus="emptyElement('status')" onblur="checkemail()" onkeyup="restrict('email')" maxlength="88" type="text" class="form-control" placeholder="Email"><span id="emailstatus"></span>

<input id="username" type="text" onfocus="emptyElement('status')" onblur="checkusername()" onkeyup="restrict('username')" maxlength="16" class="form-control" placeholder="User Name">
<span id="unamestatus"></span>

<button id="signupbtn" onclick="signup();" class="btn btn-lg btn-login btn-block">Create Account</button>
<span style="font-weight:bold;" id="status"></span>

Javascript: signup()

function signup(){
    var u = _("username").value;
    var e = _("email").value;
    var status = _("status");   

if(unamestatus.innerHTML.value != "" || emailstatus.innerHTML.value != ""){
     status.innerHTML = "Please correct your errors.";
    } else {
        _("signupbtn").style.display = "none";
        status.innerHTML = 'please wait ...';
        var ajax = ajaxObj("POST", "registration.php");
        ajax.onreadystatechange = function() {
            if(ajaxReturn(ajax) == true) {
                if(ajax.responseText != "signup_success"){
                    status.innerHTML = ajax.responseText;
                    _("signupbtn").style.display = "block";
                    location.href = "registration_success.php";
                } 
            }
        }
        ajax.send("fn="+fn+"&ln="+ln+"&u="+u+"&e="+e+"&p="+p1+"&c="+c+"&g="+g);
    }
}

Javascript: checkusername()

function checkusername(){
    var u = _("username").value;
    if(u != ""){
        //_("unamestatus").innerHTML = 'checking ...';
        var ajax = ajaxObj("POST", "registration.php");
        ajax.onreadystatechange = function() {
            if(ajaxReturn(ajax) == true) {
                _("unamestatus").innerHTML = ajax.responseText;
            }
        }
        ajax.send("usernamecheck="+u);
    }
}

Javascript: checkemail()

function checkemail(){
    var e = _("email").value;
    if(e != ""){
        //_("emailstatus").innerHTML = 'checking ...';
        var ajax = ajaxObj("POST", "registration.php");
        ajax.onreadystatechange = function() {
            if(ajaxReturn(ajax) == true) {
                _("emailstatus").innerHTML = ajax.responseText;
            }
        }
        ajax.send("emailcheck="+e);
    }
}

1 个解决方案

#1


0  

Your problem is here:

你的问题在这里:

} else if(unamestatus.innerHTML.value != "" || emailstatus.innerHTML.value != ""){
    status.innerHTML = "Please correct your errors.";
}

innerHTML does not have a value property. Use,

innerHTML没有value属性。使用,

} else if(unamestatus.innerHTML != "" || emailstatus.innerHTML != ""){
    status.innerHTML = "Please correct your errors.";
}

instead, however there are much better ways of doing this.

相反,有更好的方法来做到这一点。

#1


0  

Your problem is here:

你的问题在这里:

} else if(unamestatus.innerHTML.value != "" || emailstatus.innerHTML.value != ""){
    status.innerHTML = "Please correct your errors.";
}

innerHTML does not have a value property. Use,

innerHTML没有value属性。使用,

} else if(unamestatus.innerHTML != "" || emailstatus.innerHTML != ""){
    status.innerHTML = "Please correct your errors.";
}

instead, however there are much better ways of doing this.

相反,有更好的方法来做到这一点。