OnKeyPress Not called + JS
Code:
<asp:TextBox ID="TextBox1" runat="server" onKeyPress='return maxLength(this,"30");'></asp:TextBox>
Code:
function maxLength(field,maxChars)
{
alert('onKeyPress');
if(field.value.length >= maxChars) {
event.returnValue=false;
alert("more than " +maxChars + " chars");
return false;
}
}
When I Press any Character , maxLength function is not called,WHy SO?
Re: OnKeyPress Not called + JS
maxLength is a property of the Text Object. Browsers are assuming you want to access that property not call a function.
Since Javascript is case sensitive, changing the function name to MaxLength or maxlength will work.
Re: OnKeyPress Not called + JS
agreed
change the name of the function
Re: OnKeyPress Not called + JS
to add to what brucevde and avrail wrote, you need some kind of javascript debugger (firefox firebug is a very good one) when you work with javascript.
Re: OnKeyPress Not called + JS
i use IE8 Developer tool,
and you also should try Chrome Developer Tools it is perfect
Re: OnKeyPress Not called + JS
sonia.sardana,
I am playing catch up on some threads here, been away on holiday...
Did you get a solution to your problem? If so, can you remember to mark your thread as resolved?
Gary