Click here to Skip to main content
15,904,497 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created a function to show time...But it shows error by alert message...

my code here:::::
C#
function numonly(evt) {
           var nbr;
           var nbr = (window.event) ? event.keyCode : evt.which;
           if (nbr >=01 && nbr <=23 ) {
               return true;
           }
           else {
               alert("Mention the time correctly");
               return false;
           }
       }

I want to show time from 1 to 23....so i gave nbr>=1 ....But if i give 1 it shows error....what should i do....

thanks in advance
Posted

1 solution

<html>>
   <HEAD>
   <SCRIPT language=Javascript>
      <!--
      function isNumberKey(evt,val)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            {
  alert("Mention the time correctly");

      return false;
       }
      else
      {
         if(val>23)
      {
        return false;
          alert("Mention the time correctly");

        }
  else
      {
         return true;
       }
   }
      }
      //-->
   </SCRIPT>
   </HEAD>
   <BODY>
      <INPUT id="txtChar" onkeypress="return isNumberKey(event,this.value)" type="text" name="txtChar">
   </BODY>
</HTML>
 
Share this answer
 
v2

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