Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there a better way to code this in JavaScript and/or jQuery?
    primarykey
    data
    text
    <p>Here it is:</p> <pre><code>//Disable KeyboardNavigation document.getElementById("author").onfocus = function() { document.onkeyup = null; }; document.getElementById("email").onfocus = function() { document.onkeyup = null; }; document.getElementById("url").onfocus = function() { document.onkeyup = null; }; document.getElementById("comment").onfocus = function() { document.onkeyup = null; }; //Enable KeyboardNavigation document.getElementById("author").onblur = function() { document.onkeyup = KeyCheck; }; document.getElementById("email").onblur = function() { document.onkeyup = KeyCheck; }; document.getElementById("url").onblur = function() { document.onkeyup = KeyCheck; }; document.getElementById("comment").onblur = function() { document.onkeyup = KeyCheck; }; </code></pre> <p>I believe it's definitely possible to write a better code with a loop but I really don't know how to make it work. I tried the following:</p> <pre><code>var formfields= ["author", "email", "url", "comment"]; for (i=1; i&lt;=3; i++){ //Don't really know what to put in here. } </code></pre> <p>Thank you in advance for your help!</p> <p>EDIT : Whole code is below. You should know that <a href="https://stackoverflow.com/questions/9145461/keyboard-navigation-how-to-go-to-the-next-and-previous-element-with-arrow-keys">I got some help</a> to get to this result:</p> <pre><code>document.onkeyup = KeyCheck; var pages = [ "http://", "http://", "http://", "http://", "http://"]; function leftarrowpressed() { location.href = pages[ Math.max(0, 0 - 1) ]; //The second '0' here changes from 0 to 4, according to the page. } function rightarrowpressed() { location.href = pages[ Math.min(pages.length - 1, 0 + 1) ]; //The second '0' here changes from 0 to 4, according to the page. } function KeyCheck(e) { var KeyID = (window.event) ? event.keyCode : e.keyCode; switch(KeyID) { // left arrow key case 37: leftarrowpressed(); break; // right arrow key case 39: rightarrowpressed(); break; } } </code></pre> <p>Hope this can help a little more. By the way, thank you everyone. I really don't know which solution to choose.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload