Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
145
rated 0 times [  146] [ 1]  / answers: 1 / hits: 42307  / 11 Years ago, wed, june 12, 2013, 12:00:00

This code is not working for me in Firefox(V21.0) but works in IE(V9,V10) and Chrome (V 27.0.1453.110 m)


Method cal:


<input type="text" id="txt1" class="search-bar-input"
onkeyup="handleKeyPress('btn1');">

Method definition:


function handleKeyPress(searchButtonId) {
if (event.keyCode === 13) {
alert(event.KeyCode);
}
}

Error Message:



ReferenceError: event is not defined

if (event.keyCode === 13) {



Does anyone have any idea to solve the issue?


More From » firefox

 Answers
55

Use



<input type=text id=txt1 class=search-bar-input onkeyup=handleKeyPress(event, 'btn1');>


Then



function handleKeyPress(event) {
event = event || window.event //For IE
if (event.keyCode === 13) {
alert(event.keyCode);
}
}


Demo: Fiddle


[#77671] Tuesday, June 11, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jackie

Total Points: 442
Total Questions: 107
Total Answers: 94

Location: Honduras
Member since Sun, Dec 26, 2021
2 Years ago
jackie questions
Sat, Sep 18, 21, 00:00, 3 Years ago
Wed, Jul 14, 21, 00:00, 3 Years ago
;