4 replies [Last post]
tqmd1
tqmd1's picture
Offline
Regular
Pakistan
Last seen: 23 weeks 1 day 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: 1 hour 56 min ago
Dallas
Timezone: GMT-5
Joined: 2004-06-25
Posts: 9052
Points: 3021

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

Unplanned code results in a tangled wad of brain-cramping confusion.

There are enough html & css demos and tutorials to be interesting. Please visit.

Tony
Tony's picture
Offline
Moderator
Brisbane
Last seen: 13 hours 38 min ago
Brisbane
Timezone: GMT+10
Joined: 2003-03-12
Posts: 5054
Points: 2632

Gary you go to top of the

Gary you go to top of the class Party

balajidesign
balajidesign's picture
Offline
Enthusiast
Last seen: 26 weeks 1 day 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: 34 weeks 3 days 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