onKeyDown and onKeyUp doesnot working [Resolved]

Posted by Sahoo under JavaScript on 10/22/2012 | Points: 10 | Views : 3009 | Status : [Member] | Replies : 1
Hi,

I have a text box and want to put validation on it.My code is like :

<asp:TextBox ID="txtName" runat="server" onKeyDown="limitText(this,25);" onKeyUp="limitText(this,25);" MaxLength="25"></asp:TextBox>

function limitText(limitField, limitNum) {

if (limitField.value.length > limitNum) {
alert("my message");
limitField.value = limitField.value.substring(0, limitNum);
}
}

Here if I am using MaxLength attribute of textbox , then onKeyDown and onKeyUp are not working. I am not getting any alert.Removing MaxLength atrribute all working fine.


Any suggestion.
Thanks in advance




Responses

Posted by: Sahoo on: 10/22/2012 [Member] Starter | Points: 25

Up
0
Down

Resolved
I fixed it with by passing parameter in function 1 less than max length
value.Like

<asp:TextBox ID="txtName" runat="server" onKeyDown="limitText(this,24);" onKeyUp="limitText(this,24);" MaxLength="25"></asp:TextBox>


Sahoo, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response