By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,516 Members | 1,369 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,516 IT Pros & Developers. It's quick & easy.

keypress not working in FireFox

Claus Mygind
100+
P: 571
In the code below, the following will prevent the keypress or keydown event from firing. And I just wondering why.

1. If when the form is loaded the button is disabled.
2. The button is set active when a change occurs on the text box.
3. The button will not fire on the keypress event.

However, if the button is not disabled when the form is loaded then the event will fire. Why?

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3.  <head>
  4.   <title>Key Prss Test</title>
  5.   <script type="text/javascript">
  6.   <!--
  7.         function main()
  8.         {
  9.             this.assignEventListners = function (obj)
  10.             {
  11.                 var thisText = document.getElementById('thisText');
  12.                 if (thisText.addEventListener)
  13.                 {
  14.                     thisText.addEventListener('change', 
  15.                         function(evt)
  16.                         {
  17.                                     document.getElementById("sbRun").disabled = false;
  18. //                                    document.getElementById("sbRun").select();
  19. //                                    document.getElementById("sbRun").focus();
  20.                         },
  21.                         false)
  22.                 }
  23.                 var sbRun = document.getElementById('sbRun');
  24.                 if (sbRun.addEventListener)
  25.                 {
  26.                     sbRun.addEventListener('keydown', m.runReport, false);
  27.                 }
  28. /*
  29.                 var sbRun2 = document.getElementById('sbRun2');
  30.                 if (sbRun2.addEventListener)
  31.                 {
  32.                     sbRun2.addEventListener('keydown', m.runReport, false);
  33.                 }
  34. */
  35.             };
  36.  
  37.             this.runReport = function ()
  38.             {
  39.                 alert(document.getElementById("thisText").value);
  40.             };
  41.  
  42.         }
  43.         m = new main;
  44.  
  45.   //-->
  46.   </script>
  47.  </head>
  48.  
  49.  <body id="testKeyPress" onload="m.assignEventListners(this);">
  50.     <form method="post" action="" onSubmit="return false;">
  51.         <input type="text" id="thisText">
  52.         <input type="button" id="sbRun" value="Go1" disabled>
  53.         <!-- <input type="button" id="sbRun2" value="Go2"> -->
  54.     </form>
  55.  </body>
  56. </html>
  57.  
  58.  
May 5 '14 #1

✓ answered by Dormilich

late replay, ...

However, if the button is not disabled when the form is loaded then the event will fire.
I couldnít verify this. In every variation I tried it didnít fire a keydown event (hitting enter didnít trigger anything and a mouse click certainly doesnít fire a key event)

Share this Question
Share on Google+
2 Replies


Dormilich
Expert Mod 5K+
P: 8,639
late replay, ...

However, if the button is not disabled when the form is loaded then the event will fire.
I couldnít verify this. In every variation I tried it didnít fire a keydown event (hitting enter didnít trigger anything and a mouse click certainly doesnít fire a key event)
May 21 '14 #2

Claus Mygind
100+
P: 571
Thanks for confirming that the button event would not fire, when the initial state is disabled.
May 23 '14 #3

Post your reply

Sign in to post your reply or Sign up for a free account.