Javascript ActiveElement and Keydown Event Listener -


I'm new to JavaScript and I'm trying to scan the following code to see if the ID = "Subcommunity" is active, if not it, so i click on submit button with AD = "A" I'll click when I press 'A' on the keyboard. Now when I select the text box I get a warning, but when I do not have it selected it does not raise my keydown. Please help!

  GetActive function (if (document.activeElement.id == 'lessonNum') {Warning ('subtitle active'); Var B1 = new boolean (1); } Else {var b1 = new boolean (0); }} Document.addEventListener ("keydown", keyDownTextField, incorrect); Function keyDownTextField (e) {var keyCode = e.keyCode; If (keycode == 65) {if (b1 == 0) {Warning ('one is pressed'); . Click on Document.getElementById ('A') (); }}    

In your code:

  Gt; GetActive Function () {& gt; If (document.activeElement.id == 'lessonNum') {& gt; Warning ('subnote active'); & Gt; Var B1 = new boolean (1);   

The above line creates a local variable named B1 and specifies a new Boolean object. I think that you just want a primitive, therefore:

  var b1 = true;   

or the entire if..size statement can be changed with:

  var b1 = document.activeElement.id == 'lessonNum'; If (B1) warning ('Reading is active');   

Note that getActive is never called as b1 is never set.

You have keyDownTextField in:

  & gt; If (b1 == 0) {& gt; Warning ('one is pressed');   

However for b local GetActive , a reference error will be thrown.

For example

  (function)  

(global) {var b1; Var getActive = function () {b1 = document.activeElement & amp; Amp; Amp; Amp; Document; Active element. Id == 'lessonNum'; If (B1) warning ('Reading is active');} global GetActive = getActive; Var keyDownTextField = function (e) {e = E || Window.event; Var keycode = e.keyCode || E.which; If (keycode == 65) {getActive (); // should click here? If (B1) {Warning ('A is suppressed'); Document. GetElementById ('A'). Click ();}}} global.keyDownTextField = keyDownTextField;} (this)); Window.onload = function () {addEvent (document, 'keydown', keyDownTextField); }; // Just an assistant function addEvent (L, EVT, FN) {if (el.addEventListener) {el.addEventListener (evt, fn, false); } Else if (el.attachEvent) {el.attachEvent ('on' + evt, fn); }}

Comments

Popular posts from this blog

java - NullPointerException for a 2d Array -

python - Assemble mpeg file unable to play in mediaplayer -

c# - NameSpace Manager or XsltContent to parse aspx page -