Home Web Front-end JS Tutorial Examples to explain js method to verify whether form items are empty_javascript skills

Examples to explain js method to verify whether form items are empty_javascript skills

May 16, 2016 pm 03:20 PM
js form verify

Form verification is essential for almost every website that requires registration or login. Some verifications are very complicated and can be said to be various requirements for you. However, this chapter only introduces the simplest form. The verification method is to determine whether it is empty. Some websites with lower requirements have already met this need.
The code is as follows:

<html> 
<head> 
<meta charset="gb2312"> 
<title>js简单表单验证</title> 
<script type="text/javascript">
window.onload=function()
{
 var bt=document.getElementById("bt");
 bt.onclick=function()
 {
  if(document.myform.name.value=="")
  {
   alert("用户名不能为空!");
   document.myform.name.focus();
   return false;
  } 
  else if(document.myform.pw.value=="")
  {
   alert("密码不能为空!");
   document.myform.pw.focus();
   return false; 
  }
 }
}
</script>
</head>
<body>
<form action="index.php" method="get" name="myform">
<ul>
 <li>姓名:<input type="text" name="name" id="name" /></li>
 <li>密码:<input type="text" name="pw" id="age" /></li>
 <li><input type="submit" id="bt"/></li>
</ul>   
</form>
</body>
</html>
Copy after login

The above is the detailed content of this article, I hope it will be helpful to everyone’s study.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to verify signature in PDF How to verify signature in PDF Feb 18, 2024 pm 05:33 PM

How to verify signature in PDF

Detailed method to unblock using WeChat friend-assisted verification Detailed method to unblock using WeChat friend-assisted verification Mar 25, 2024 pm 01:26 PM

Detailed method to unblock using WeChat friend-assisted verification

Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS Dec 17, 2023 pm 06:55 PM

Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS

Recommended: Excellent JS open source face detection and recognition project Recommended: Excellent JS open source face detection and recognition project Apr 03, 2024 am 11:55 AM

Recommended: Excellent JS open source face detection and recognition project

New features in PHP 8: Added verification and signing New features in PHP 8: Added verification and signing Mar 27, 2024 am 08:21 AM

New features in PHP 8: Added verification and signing

PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts Dec 18, 2023 pm 03:39 PM

PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts

How to create a stock candlestick chart using PHP and JS How to create a stock candlestick chart using PHP and JS Dec 17, 2023 am 08:08 AM

How to create a stock candlestick chart using PHP and JS

How to solve the problem of steam login stuck in mobile token verification? How to solve the problem of steam login stuck in mobile token verification? Mar 14, 2024 pm 07:35 PM

How to solve the problem of steam login stuck in mobile token verification?

See all articles