Alert Not Displaying In Js
alert is not working as expected! i don't know why... I am trying to evaluate a form on client side. I have tried getElementsById, getElementsByName. Where am i going wrong? I am s
Solution 1:
- Spelling of alret and indexOf !
- getElementById is singular
- submitOK="false" sets submitOK to true since a non-empty string is truthy. use
submitOK=false
- you did not return submitOK when you asked the question
functionvalidate() {
var uname = document.getElementById("uname").value;
var email = document.getElementById("email").value.indexOf('@');
var pass = document.getElementById("pass").value;
var rpass = document.getElementById("rpass").value;
submitOK = true;
if (uname.length == 0) {
alert("Username cannot be empty")
submitOK = false;
}
if (email == -1) {
alert("Not a valid email");
submitOK = false;
}
if (pass.length === 0) {
alert("Password cannot be empty");
submitOK = false;
}
if (pass != rpass) {
alert("passwords don't match");
submitOK = false;
}
return submitOK;
}
<h1>Register</h1><br /><formaction="RegInt.jsp"method="post"onsubmit="return validate()">
Enter UserName :
<inputtype="text"name="uname"id="uname"value='${ param.uname}'placeholder="Enter Name"><br/><br/>Enter Email:
<inputtype="email"name="email"id="email"value='${param.email}'placeholder="Enter Email"><br/><br/>Enter Password:
<inputtype="password"name="pass"id="pass"value='${param.pass}'placeholder="Enter password"><br/><br/>Repeat Password:
<inputtype="password"name="rpass"id="rpass"value='${param.rpass}'placeholder="Repeat Password" /><br/><br/><br/><inputtype="submit" /></form>
Solution 2:
First check the spelling s and correct them. Then comment all the feilds and start troubleshooting them line by line. You will win. Regards !
Post a Comment for "Alert Not Displaying In Js"