The cursor is in the corresponding table item when the table item content is empty

Source: Internet
Author: User

The cursor is located in the corresponding table item when the table item content is empty:
In the case of form validation, generally, if a form item does not pass validation, then this form item will get the focus, the position of the cursor will be in this form project, the following is a brief introduction to how to achieve the sub-effect.
The code example is as follows:

<!DOCTYPE HTML><HTML><Head><MetaCharSet= "Utf-8"><Metaname= "Author"content= "http://www.51texiao.cn/" /><title>Ant Tribe</title><Scripttype= "Text/javascript">functionChkform () {if(document.getElementById ("username"). Value=="") {alert ("the user name cannot be empty! "); document.getElementById ("username"). focus (); return false; } if(document.getElementById ("PW"). Value=="") {alert ("The password cannot be empty! "); document.getElementById ("PW"). focus (); return false; }}</Script></Head><Body><formAction= "Http://www.softwhy.com"name= "MyForm"> <Table>  <TR>   <TD>User name:</TD>   <TD><inputtype= "text"name= "username"ID= "username" /></TD>  </TR>  <TR>   <TD>Password:</TD>   <TD><inputtype= "Password"name= "PW"ID= "PW" /></TD>  </TR>  <TR>   <TDcolspan= "2"><inputtype= "Submit"value= "Submit"></TD>  </TR> </Table></form></Body></HTML>

In the above code, if the user name or password does not pass the validation, then the corresponding table item will get the focus, that is, the cursor inside. The way to do this is to call the object's focus () function so that the current object gets focus.

The original address is: http://www.51texiao.cn/javascriptjiaocheng/2015/0428/304.html

The most original address is: http://www.softwhy.com

The cursor is in the corresponding table item when the table item content is empty

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.