Effect:
Input:
Textarea:Up to 100 characters
Source code:
Input: < Input Name = "Textfield" Type = "Text" Maxlength = "20" Value = "Enter Text .." Onfocus = "If (value = 'enter the text...') {value = ''}" Onblur = "If (value ='') {value = 'enter the text ..'}" /> < BR > < BR > Textarea: < Textarea Cols = "50" Rows = "5" ID = "Textarea" Onkeydown = "Textdown (event )" Onkeyup = "Textup ()" Onfocus = "If (value = 'limited to 100 words') {value = ''}" Onblur = "If (value ='') {value = 'only 100 words '}" > Up to 100 characters </ Textarea > < Script Type = "Text/JavaScript" > Function Textdown (e) {textevent = E; If (Textevent. keycode = 8 ){ Return ;} If (Document. getelementbyid ( ' Textarea ' ). Value. Length > = 100 ) {Alert ( " Hero, show your mercy. The words are limited to 100 characters. " ) If ( ! Document. All) {textevent. preventdefault ();} Else {Textevent. returnvalue = False ;}}} Function Textup (){ VaR S = Document. getelementbyid ( ' Textarea ' ). Value; // Determines whether the number of words in the text area with the ID of text exceeds 100. If (S. Length > 100 ) {Document. getelementbyid ( ' Textarea ' ). Value = S. substring ( 0 , 100 );}} </ Script >