Errant PostBack - Numeric TextBox Javascript

P

Phillip Ian

I have a textbox that I'm trying to limit to numeric entry (damn you
Microsoft for not including it in .NET!)

I've found sample code and come up with this as a solution:

<asp:TextBox id="fldQty" runat="server" CssClass="ThreePlaceInput"
MaxLength="3" Text='<%# DataBinder.Eval(Container, "DataItem.Qty") %>'
onKeyPress="javascript:return AllowOnlyNumbers();">

The Javascript looks like this:

<script language='javascript'>
<!--
function AllowOnlyNumbers() {
return ((event.keyCode >= 48) && (event.keyCode <= 57)) ||
(event.keyCode = 13);
}
-->
</script>

Now, for some reason, pressing a key that isn't accepted by the
function (non-numeric) is causing a postback. Obviously, this isn't
the intended result.

Also, this method doesn't seem to work at all in Firefox or Opera.
Anything I can do there?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,177
Latest member
OrderGlucea
Top