
var a=document.check.username.value; if(a=="" ) { alert("Enter a valid UserName"); return false; } if(!isNaN(a) ) { alert("Enter a valid UserName"); return false; } var b=document.check.password.value; if(b=="") { { alert("Enter password"); return false; } }

The given code allow the user to enter username and password.It will show an error message if user leave the fields blank.
<script>
function validate(){
var a=document.form.username.value;
if(a=="" ) {
alert("Enter a valid UserName");
return false;
}
if(!isNaN(a) )
{
alert("Enter a valid UserName");
return false;
}
var b=document.form.password.value;
if(b=="") {
{
alert("Enter password");
return false;
}
}
}
</script>
<form name="form" method="post" action="" onsubmit="return validate();">
<table>
<tr>
<td>Username:</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<tr>
<td></td>
<td>
<input type="submit" value="Submit" name="addproduct"/>
</td>
</tr>
</table>
</form>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.