Hi,
I have some javascript code that im trying to use so as to prevent users from entering any characters except for numbers in to a ASP textbox. Im trying to call this function on the "onkeypress" of the HTML table however it doesnt seem to be working.Below is the code im trying
Any help would be great.Thanks
<head runat="server">
<title>Score Card</title>
<script language=javascript type="text/javascript">
function NumberOnly()
{
//only accept numbers
if (event.keyCode>=48 && event.keyCode<=57)
{
event.returnValue=true;
}
else
{
event.returnValue=false;
}
}
</script>
</head>
<table border="1" width="100%" onkeypress="NumberOnly">
<tr>
<td width="10%"><asp:Label ID="Label3" runat="server" Text="Hole 1"></asp:Label></td>
<td width="10%"><asp:Label ID="Label4" runat="server" Text="Par 4"></asp:Label></td>
<td width="10%"><asp:Label ID="Label18" runat="server" Text="Index 16"></asp:Label></td>
<td width="10%"><asp:TextBox ID="txtHole1" runat="server" AutoPostBack="True" Width="75px" OnTextChanged="txtHole1_TextChanged"></asp:TextBox></td>
</tr>
</table>
I have some javascript code that im trying to use so as to prevent users from entering any characters except for numbers in to a ASP textbox. Im trying to call this function on the "onkeypress" of the HTML table however it doesnt seem to be working.Below is the code im trying
Any help would be great.Thanks
<head runat="server">
<title>Score Card</title>
<script language=javascript type="text/javascript">
function NumberOnly()
{
//only accept numbers
if (event.keyCode>=48 && event.keyCode<=57)
{
event.returnValue=true;
}
else
{
event.returnValue=false;
}
}
</script>
</head>
<table border="1" width="100%" onkeypress="NumberOnly">
<tr>
<td width="10%"><asp:Label ID="Label3" runat="server" Text="Hole 1"></asp:Label></td>
<td width="10%"><asp:Label ID="Label4" runat="server" Text="Par 4"></asp:Label></td>
<td width="10%"><asp:Label ID="Label18" runat="server" Text="Index 16"></asp:Label></td>
<td width="10%"><asp:TextBox ID="txtHole1" runat="server" AutoPostBack="True" Width="75px" OnTextChanged="txtHole1_TextChanged"></asp:TextBox></td>
</tr>
</table>