4 replies [Last post]
tqmd1
tqmd1's picture
User offline. Last seen 17 weeks 2 days ago. Offline
rank Regular
Regular
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
User offline. Last seen 15 min 11 sec ago. Offline
rank Moderator
Moderator
Timezone: GMT-5
Joined: 2004-06-25
Posts: 7921
Points: 1760

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
User is online Online
rank Moderator
Moderator
Timezone: GMT+10
Joined: 2003-03-12
Posts: 3794
Points: 1227

Gary you go to top of the

Gary you go to top of the class Party

Your question may have already been answered, search and read before you ask.

balajidesign
balajidesign's picture
User offline. Last seen 6 weeks 5 days ago. Offline
rank Enthusiast
Enthusiast
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
User offline. Last seen 2 weeks 3 days ago. Offline
rank Moderator
Moderator
Timezone: GMT+10
Joined: 2004-05-01
Posts: 8139
Points: 1321

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