4 replies [Last post]
tqmd1
tqmd1's picture
Offline
Regular
Pakistan
Last seen: 1 year 27 weeks ago
Pakistan
Timezone: GMT+5
Joined: 2011-10-15
Posts: 15
Points: 31

Dear Experts

In following codes alert() does not work, please check what is wrong?

<script language="javascript">
 
function isNumberKey(evt)
    {
   var charCode = (evt.which) ? evt.which : event.keyCode;
    if (charCode > 31 && (charCode < 48    || charCode > 57))
{
      return false;
}
else
{
   return true;
alert("Only Numeric")
       }
}
 
</script>

Tags:
gary.turner
gary.turner's picture
Offline
Moderator
Dallas
Last seen: 14 hours 47 min ago
Dallas
Timezone: GMT-5
Joined: 2004-06-25
Posts: 9583
Points: 3649

Homework?

This looks very much like a class assignment. You're supposed to work these problems out for yourself.

However, I'm bored at the moment, so …

You have this,

else {
   return true;
   alert("Only Numeric")
}
The alert() function is never seen. You think maybe it should come before the return function?

I didn't look at the decision part, so if there's a problem there, :shrug:

cheers,

gary

If your web page is as clever as you can make it, it's probably too clever for you to debug or maintain.

Tony
Tony's picture
Offline
Moderator
Brisbane
Last seen: 1 day 1 hour ago
Brisbane
Timezone: GMT+10
Joined: 2003-03-12
Posts: 5318
Points: 2939

Gary you go to top of the

Gary you go to top of the class Party

balajidesign
balajidesign's picture
Offline
Enthusiast
Last seen: 2 years 49 weeks ago
Timezone: GMT+5.5
Joined: 2012-01-31
Posts: 116
Points: 124

once the value will return by

once the value will return by return true; it will not coming up again. we need to put that alert message before that return statement.

like this:

<script language="javascript">
 
function isNumberKey(evt)
    {
   var charCode = (evt.which) ? evt.which : event.keyCode;
    if (charCode > 31 && (charCode < 48    || charCode > 57))
{
alert("its fine now");
      return false;
}
else
{
alert("Only Numeric");
return true;
       }
}
 
</script>

Tyssen
Tyssen's picture
Offline
Moderator
Brisbane
Last seen: 1 year 50 weeks ago
Brisbane
Timezone: GMT+10
Joined: 2004-05-01
Posts: 8201
Points: 1386

Why are you reviving 3-month-old threads?

Stare

How to get help
Post a link. If you can't post a link, jsFiddle it.
My blog | My older articles | CSS Reference