JavaScript Simple form verification: Is the username and password empty
form Form code
<form name="form1" method="post" action="">
username: <input name="user" type="text" id="user">
password: <input name="pwd" type="password" id="pwd">
<input type="button" name="button" value="Log in" onclick="check()">
<input type="reset" value="Reset" >
</form>
Customize JavaScript function check()
<script language="javascript">
function check(){
if(form1.user.value==""){
alert("Please enter your username!" );
form1.user.focus();
return;
} else if (form1.pwd.value=="") {
alert("Please enter your password!" );
form.pwd.focus();
return;
} else {
form1.submit();
}
}
</script>
Example 2
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<form action="" name="my_form" onsubmit="return check_form(this)">
username: <input type="text" name="username"><br> password:
<input type="text" name="password">
<input type="submit" value="Log in" ><input type="reset" value="Clear" >
</form>
<script>
function check_form(form) {
if (form.username.value == "") {
alert("Username is empty" )
form.username.focus();
return false;
}
if (form.password.value == "") {
alert("Password is empty" )
form.password.focus();
return false;
}
return true;
}
</script>
</body>
</html>
Here is just a simple JavaScript Form verification, regular expressions can also be added to expand to more reasonable verification;

The above is shared by Suyou.com with everyone." JavaScript Simple form verification: Is the username and password empty? Thank you very much for your patience to read this article. We will provide you with more information on reference, use or learning communication.We can also provide you with:Enterprise website construction, website imitation, website copying, imitation site, foreign trade website construction, foreign trade website construction, company official website productionFor services, our company serves customers with the service concept of "integrity, professionalism, pragmatism and innovation".If you need cooperation, please scan the code to consult, and we will serve you sincerely.
TAG Label: