When calling the validateNumber function this way
OnClientClick="return validateNumber(this.txtshift,'This Works',1,3);"
this.txtshift does not refer to a TextBox txtshift, it refers instead to a property of the Button named txtshift.
Try it this way:
1. Remove the OnClientClick event handler from the Designer (HTML view).
<asp:Button ID="Button1" runat="server" Text="Button" UseSubmitBehavior="False" />
2. In the CodeBehind, Page_Load event handler, add this:
Button1.OnClientClick = "return validateNumber('" + txtshift.ClientID + "','This Works',1,3);"
3. Change your function as follows:
function validateNumber(fieldId, msg, min, max)
{
var field = document.GetElementById(fieldId);
if (!min)
{
min = 0;
}
if (!max)
{
max = 255;
}
if ( (parseInt(field.value) != field.value) || field.value.length < min || field.value.length > max )
{
alert(msg);
field.focus();
field.select();
return false;
}
return true;
}
NC...