469,317 Members | 1,861 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,317 developers. It's quick & easy.

keypress not working in FireFox

Claus Mygind
571 512MB
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)

2 2161
Dormilich
8,651 Expert Mod 8TB
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
571 512MB
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.

Similar topics

4 posts views Thread by sonic_soul | last post: by
6 posts views Thread by rich_poppleton | last post: by
3 posts views Thread by Darryn Ross | last post: by
4 posts views Thread by Dave (DreamIsle) | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.