我有文本框,其值是根据电子邮件ID是否存在而设置的。问题是它第一次点击时没有设置值,但第二次点击它设置值。问题在于以下代码中的电子邮件字段
function CheckValidationSignup() {
var Name = NameValidation();
//var Email = EmailValidation();
var password = passwordValidation();
var cnfrmpwd = CnfrmPasswordValidation();
var mbileno = MobileNoValidation();
EmailValidation(); ***//This function doesnot set value and below line gives me value empty for first click and then it gives correct value on 2nd click***
var Email = document.getElementById('EmailChk').value;
var emailchk
if (Email == 'valid') {
emailchk = true;
} else {
emailchk = false;
}
if (Name && password && cnfrmpwd && mbileno && emailchk) {
var VerificationCode = getRandomInt(1, 999999);
var Name = document.getElementById('Name').value;
var Email = document.getElementById('Email').value;
var Password = document.getElementById('Password').value;
var MobileNo = document.getElementById('MobileNo').value;
$.ajax({
url: "@Url.Action("SaveNewUser", "Login")",
dataType: "json",
data: { name: Name, email: Email, password: Password, mobile_no: MobileNo,verification_code: VerificationCode},
success: function (result) {
$("#signup").hide();
$("#verificationcode").show();
},
error: function (result) {
alert("Error Msg:" + result);
}
});
}
}
function EmailValidation() {
var Email = document.getElementById('Email').value;
var div = document.getElementById('EmailValidation');
if (!isValidEmailAddress(Email)) {
div.innerHTML = '<font color="red" id="nameValidationFalse"><i class="fa fa-times-circle"></i> Please enter valid Email address</font>';
document.getElementById("EmailChk").value = "invalid"
return false;
}
else {
$.ajax({
url: "@Url.Action("EmailIdExistsCheck", "Login")",
dataType: "json",
data: { email_id: Email},
success: function (result) {
$.each(result, function (index, item) {
if (item.email_id_check == 0) {
div.innerHTML = '<font color="green" id="nameValidationFalse"><i class="fa fa-check-circle"></i> ' + Email + ' is Verified</font>';
document.getElementById("EmailChk").value = "valid"
return true;
}
else {
div.innerHTML = '<font color="red" id="nameValidationFalse"><i class="fa fa-times-circle"></i> Email address already exists</font>';
document.getElementById("EmailChk").value = "invalid"
return false;
}
});
},
error: function (result) {
alert("Error Msg:" + result);
}
});
}
return true;
}
Html代码
<form action="#">
<div>
<input id="Name" type="text" onkeydown="if (event.keyCode == 13) CheckValidationSignup();" placeholder="Name*" />
<div id="nameValidation"></div>
@*<font color="green" id="nameValidationTrue"><i class="fa fa-check-circle"></i></font>
<font color="red" id="nameValidationFalse"><i class="fa fa-times-circle"></i></font>*@
</div>
<input id="Email" type="email" onkeydown="if (event.keyCode == 13) CheckValidationSignup();" placeholder="Email Address*" />
<div id="EmailValidation"></div>
<input id="EmailChk" type="text" style="display:none;"name="emailchk" />
<input id="Password" type="password" onkeydown="if (event.keyCode == 13) CheckValidationSignup();" placeholder="Password*" />
<div id="PasswordValidation"></div>
<input id="CnfrmPassword" type="password" onkeydown="if (event.keyCode == 13) CheckValidationSignup();" placeholder="Confirm Password*" />
<div id="ConfirmPasswordValidation"></div>
<input id="MobileNo" type="tel" onkeydown="if (event.keyCode == 13) CheckValidationSignup();" placeholder="Mobile No*" />
<div id="PhoneNoValidationValidation"></div>
<div class="text-center"><a class="beta-btn primary" href="#" onclick="CheckValidationSignup()">Signup <i class="fa fa-chevron-right"></i></a>
<a class="beta-btn primary" href="#" onclick="ActivateAccount()">Enter Verification Code <i class="fa fa-chevron-right"></i></a></div>
</form>
我尝试删除<form>