N
Not Me
Hi there,
There are hundreds of messages with different solutions on how to limit
the number of characters for a text box in ASP.net, none of which I can
get to work!!
I do lie, because using asp validators I can get a quick solution, but
I'd rather prevent the user from entering the characters in the first
place, rather than just telling them they've entered too much.
Many solutions tell me to use onkeydown etc. in the textbox parameters
- when I do this I get errors saying it's not allowed.. I seem to be
able to use attributes.add but nothing happens then. Also I'm being
told I need a 'type' parameter in my script, wheras all of the examples
just use 'language'..
here's my example code anyway, which is 'attached' to the textbox by
attributes.add.
<script type="text/jscript" language="jscript">
function LimitMultiLineLength(obj)
{
var iKey;
var eAny_Event = window.event;
iKey = eAny_Event.keyCode;
var re
re = new RegExp("\r\n","g")
x = obj.value.replace(re,"").length ;
if ((x >= obj.maxLength) && ((iKey > 33 && iKey <
255) || (iKey > 95 && iKey < 106)) && (iKey != 13))
{
if (obj.ErrorMessage )
{
alert(obj.ErrorMessage);
}
window.event.returnValue=false;
}
}
</script>
whereas nothing happens in IE, firefox is kind enough to tell me that
'LimitMultiLineLength is not defined' - so I'm guessing at least it's
being looked for.
any ideas? I thought there'd be a really simple solution to this!
(maybe there is...)
Cheers,
Chris
There are hundreds of messages with different solutions on how to limit
the number of characters for a text box in ASP.net, none of which I can
get to work!!
I do lie, because using asp validators I can get a quick solution, but
I'd rather prevent the user from entering the characters in the first
place, rather than just telling them they've entered too much.
Many solutions tell me to use onkeydown etc. in the textbox parameters
- when I do this I get errors saying it's not allowed.. I seem to be
able to use attributes.add but nothing happens then. Also I'm being
told I need a 'type' parameter in my script, wheras all of the examples
just use 'language'..
here's my example code anyway, which is 'attached' to the textbox by
attributes.add.
<script type="text/jscript" language="jscript">
function LimitMultiLineLength(obj)
{
var iKey;
var eAny_Event = window.event;
iKey = eAny_Event.keyCode;
var re
re = new RegExp("\r\n","g")
x = obj.value.replace(re,"").length ;
if ((x >= obj.maxLength) && ((iKey > 33 && iKey <
255) || (iKey > 95 && iKey < 106)) && (iKey != 13))
{
if (obj.ErrorMessage )
{
alert(obj.ErrorMessage);
}
window.event.returnValue=false;
}
}
</script>
whereas nothing happens in IE, firefox is kind enough to tell me that
'LimitMultiLineLength is not defined' - so I'm guessing at least it's
being looked for.
any ideas? I thought there'd be a really simple solution to this!
(maybe there is...)
Cheers,
Chris