/    Sign up×
Community /Pin to ProfileBookmark

key press event code not running in mozilla

hi all,

i wrote code to block alphabets in a input text box, this is working perfectly in IE, but when I tried with mozilla fire fox its not working properly.

this is the code I used…
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN”
http://www.w3.org/TR/html4/strict.dtd“>

<html>
<head>

<script type=”text/javascript”>

if(navigator.appName!= “Mozilla”)
{

}
else{document.addEventListener(“keypress”,keyhit,true);}

onload = function(){
field = document.getElementById(‘number_field’)
field.onkeydown = keyhit
field.focus()
}

function keyhit(e)
{
thisKey = e ? e.which : window.event.keyCode

if(thisKey == ’65’ || thisKey == ’66’ || thisKey == ’67’ || thisKey == ’68’ || thisKey == ’69’ || thisKey == ’70’ || thisKey == ’71’ || thisKey == ’72’ || thisKey == ’73’ || thisKey == ’74’ || thisKey == ’75’ || thisKey == ’76’ || thisKey == ’77’ || thisKey == ’78’ || thisKey == ’79’ || thisKey == ’80’ || thisKey == ’81’ || thisKey == ’82’ || thisKey == ’83’ || thisKey == ’84’ || thisKey == ’85’ || thisKey == ’86’ || thisKey == ’87’ || thisKey == ’88’ || thisKey == ’89’ || thisKey == ’90’ )
{
event.returnValue = false;
alert (‘alphebets r not allowed’);
}

}

</script>

<title>increment field</title>
</head>
<body>

<form action=”” method=”post”>
<p><input type=”text” id=”number_field” name=”number_field” value=”0″></p>
</form>

</body>
</html>

please help me as soon as possible, thanks in advance…

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@CoyotelabOct 01.2008 — [CODE]if(navigator.appName!= "Mozilla")
{
[COLOR="Red"]do what?[/COLOR]
} [/CODE]
×

Success!

Help @micprasanna spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...