0

I have following working JavaScript code in my html page.

   <SCRIPT language='Javascript'>
           function isNumberKey(evt)
          {
             var charCode = (evt.which) ? evt.which : event.keyCode
             if (charCode > 31 && (charCode < 48 || charCode > 57))
                return false;

             return true;
          }         
       </SCRIPT>    

But I heard language="javascript" is deprecated so tried changing language="text/javascript" with same code as below but not working.

<SCRIPT language="text/javascript">
      function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;
      }
   </SCRIPT>

Could anyone please let me how to make the code workable in language="text/javascript" mode ?

logan
  • 7,946
  • 36
  • 114
  • 185

3 Answers3

6

Even better (since it's shorter and easier to read):

<script>
    //Some script
</script>

From the spec, emphasis added:

The type attribute gives the language of the script or format of the data. If the attribute is present, its value must be a valid MIME type. The charset parameter must not be specified. The default, which is used if the attribute is absent, is "text/javascript".

Stephen Thomas
  • 13,843
  • 2
  • 32
  • 53
1

Usually this is the right way:

<script type="text/javascript">
    //Some script
</script>
tweray
  • 1,002
  • 11
  • 18
1

Try using:

<script type="text/javascript"></script>`
Katpoes
  • 209
  • 1
  • 11