The number of words in a JavaScript record text box to detect changes in text

Source: Internet
Author: User

One of the most recent problems in doing a project to the text box in the user input text to be recorded, shown below, because we do is a text messaging platform, now our country's SMS service, if your message exceeds 70 characters, SMS will press two to you issued. So ask us to show the user how many words he entered. So that users know that my message will be divided into several.

In the net a code, put up, start to use, also OK, good, but after using a period of time found the problem. Is that you delete text, the number of words above changes there is a problem, and then studied a bit, to find out where the problem lies. Onkeydown= "Showlen (This)" onkeyup= "Showlen (this) has been used only one method at a time, and no one has used it, these two methods are counted when you press the keyboard and release the keyboard, okay, I'll put the program up.

1 2 3 4 5 6 7 8 9 <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >  <HTML>  <HEAD>  <title > New Document </TITLE>  <meta name= "generator" content= "EditPlus" >  <meta name= "Author" Content= "" >  <meta name= "Keywords" content= "" >  <meta name= "Description" content= "" >  <mce:script language= "javascript" ><!--  function Showlen (obj)   {  document.getElementById (" Contentlen ") .value=obj.value.length;  document.getElementById (" Smsnum "). Value=math.floor (obj.value.length/ +1; } //--></mce:script>  </HEAD>  <BODY>     < TextArea name= "content" cols= "rows=" "5" id= "Content" onkeydown= "Showlen (This)" onkeyup= "Showlen (This)" >
Related Article

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.