<body>
<div class="wrap">
<!-- strat-contact-form -->
<script language="JavaScript" type="text/javascript">
function checkMobileNumber(){
alert("function");
var phone = document.getElementbyId('phonenumber').value;
console.log("resp: "+phone);
var bool = isNaN(phone);
if(!bool)
document.getElementbyId.innerHTML = "Enter valid Mobile Number";
}
};
</script>
<div class="contact-form">
<!-- start-form -->
<form class="contact_form" action="RegistrationServlet" method="post" name="contact_form">
<h1>Sign Up for New Account</h1>
<ul>
<li>
<input type="email" class="textbox1" name="email" placeholder="info@resumeBuilder.com" required />
<span class="form_hint">Enter a valid email</span>
<p><img src="images/contact.png" alt=""></p>
</li>
<li>
<input type="password" name="website" class="textbox2" placeholder="password" required />
<p><img src="images/lock.png" alt=""></p>
</li>
<li>
<input type="text" class="textbox1" id = "phonenumber" name="phonenumber" placeholder="Mobile Number" onkeyup="checkMobileNumber()" onchange="checkMobileNumber()" required/>
<span class="form_hint">Enter your Mobile Number</span>
<span class="form_hint_error" id = "error"></span>
</li>
</ul>
<input type="submit" name="Sign Up" value="Sign Up"/>
<div class="clear"></div>
<div class="clear"></div>
</form>
<!-- end-form -->
<div class="clear"></div>
</div>
<!-- end-contact-form -->
</div>
</body>
</html>
当我尝试运行这个OnkeyUp并且onchange在我尝试这个并且警报没有工作时不起作用我理解该功能本身没有被调用请有人帮助。
答案 0 :(得分:1)
function checkMobileNumber(){
alert("function");
var phone = document.getElementById("phonenumber").value;
console.log("resp: "+phone);
var bool = isNaN(phone);
if(bool){
alert("Enter valid Mobile Number");
}
}
<div class="contact-form">
<!-- start-form -->
<form class="contact_form" action="RegistrationServlet" method="post" name="contact_form">
<h1>Sign Up for New Account</h1>
<ul>
<li>
<input type="email" class="textbox1" name="email" placeholder="info@resumeBuilder.com" required />
<span class="form_hint">Enter a valid email</span>
<p><img src="images/contact.png" alt=""></p>
</li>
<li>
<input type="password" name="website" class="textbox2" placeholder="password" required />
<p><img src="images/lock.png" alt=""></p>
</li>
<li>
<input type="text" class="textbox1" id = "phonenumber" name="phonenumber" placeholder="Mobile Number" onkeyup="checkMobileNumber()" onchange="checkMobileNumber()" required/>
<span class="form_hint">Enter your Mobile Number</span>
<span class="form_hint_error" id = "error"></span>
</li>
</ul>
<input type="submit" name="Sign Up" value="Sign Up"/>
<div class="clear"></div>
<div class="clear"></div>
</form>
<!-- end-form -->
<div class="clear"></div>
</div>
<!-- end-contact-form -->
答案 1 :(得分:0)
乍一看,你错过了checkMobileNumber函数中if块的开放花括号。所以这一行:
if(!bool)
应该是
if(!bool) {
。