Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Numbers Only Problem

Status
Not open for further replies.

liamba

Technical User
Jan 6, 2007
21
IE
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>

 
Was the validator still firing even if correct values were entered? If that is the case, then you set the validator up incorrectly. aspgreat's example will work perfectly.

Jim
 
yeah it fired when there was both a correct and incorrect value enterd.then when a correct value was entered the error message still appeared.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top