Is there a better way to code this in JavaScript and/or jQuery?
<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="http://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>
