Saturday, April 25, 2009

Count wordin textbox

TO find the enter text in text box use the following function in javascript Use onkeydown and onkeyup events to call this function

function fnCheckCharacters()    
{         
    var txtcheck=document.getElementById('<%= txtQ11.ClientID %>'); 
    //here txtQ11 is my textbox id       
    var lblLeftCount = document.getElementById('<%=lblCharCounter.ClientID %>'); 
    //lblCharCounter is a labed on which i printed the remaing word                
    var len=300;       
    var Lchar = 0;           
    if (txtcheck.value.length > 300)       
    {           
        alert ("You can enter atmost 300 characters");           
        txtcheck.value=txtcheck.value.substring(0,300);       
    }
    else       
    {           
        lblLeftCount.innerHTML=txtcheck.value.length;       
    }          
}   

in this function, i fixed the length of textbox to 300. user can enter only 300 char.after inserting each char, reaming one is displayed on label.


thnx

No comments:

Post a Comment

Ideal SQL Query For Handling Error & Transcation in MS SQL

BEGIN TRY BEGIN TRAN --put queries here COMMIT; END TRY BEGIN CATCH IF @@TRANCOUNT>0 BEGIN SELECT @@ERROR,ERRO...