Click here to Skip to main content
15,914,642 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I used a javascript for only type numbers. Textboxname as txtFromDay.
But now I can't type any. Because of script returns false.
U used a alert() method for display the typed data,But It result as blank message. What is the reason and solution.
script as below
C#
function Checkprice(e)
    {
    var ups=document.getElementById('<%=txtFromDay.ClientID%>').value;
                     if (e.keyCode >= 48 & e.keyCode <= 57)
                        {
                        alert(ups);
                           return true;
                        }
                    else
                        {
                        alert(ups);
                        return false;
                        }
    }
Posted

You are using a bitwise AND .....

if (e.keyCode >= 48 & e.keyCode <= 57)


You need a logical AND ..... (two &'s)

if (e.keyCode >= 48 && e.keyCode <= 57)
 
Share this answer
 
maybe best way to check if your textbox value is number and don't lost your time, to use "RegularExpressionValidator"

see here Only Number validation in Textbox of ASP.NET Using Regular Expression validator
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900