Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
95
rated 0 times [  102] [ 7]  / answers: 1 / hits: 51795  / 10 Years ago, fri, september 26, 2014, 12:00:00

I am trying to validate the textbox in the login Xhtml and once I figured out the code, the section class'container' in the code is not working.



How can I write the code and validate the textbox properly?



<head>
<script type = 'text/javascript'>
function validate() {
if (document.getElementById(login).value == ) {
alert(User name may not be blank);
} else if (document.getElementById(password).value == ) {
alert(Password may not be blank.);
}
}
</script>
<title>Login Form</title>
<link rel=stylesheet href=css/style.css/>
</head>
<body>
<h1> Login</h1>
<section class=container>
<div>
<form method=post action=index.xhtml onsubmit=return validate();>
<p>
<input type=text name=login value= id=login placeholder=Username or Email />
<input type=password name=password value= id=password placeholder=Password />
</p>
<p>
<label>
<input type=checkbox name=remember_me id=remember_me />Remember me on this computer
</label>
</p>
<p class=submit>
<input type=submit name=commit value=Login onclick=validate(); />
<button type=reset value=Clear>Clear</button>
</p>
</form>
<form action= http://localhost:8080/ChattBank/LoginServlet method=post/>
</div>
</section>
</body>

More From » html

 Answers
11

EDIT



Try this: (Replace your forms with this)



<input type=text name=login value= id=login placeholder=Username or Email  />
<input type=password name=password value= id=password placeholder=Password />
</p>
<p>
<label>
<input type=checkbox name=remember_me id=remember_me />Remember me on this computer</label>
</p>
<p class=submit>
<input type=submit name=commit value=Login onclick=validate(); />
<button type=reset value=Clear>Clear</button>
</p>
<script>
function validate() {
if (document.getElementById(login).value == ) {
alert(User name may not be blank);
} else if (document.getElementById(password).value == ) {
alert(Password may not be blank.);
}
}
</script>


Here is a working fiddle


[#69332] Tuesday, September 23, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
carolyn

Total Points: 618
Total Questions: 119
Total Answers: 86

Location: Saint Pierre and Miquelon
Member since Fri, Jan 28, 2022
2 Years ago
;