How to call function when I press tab key in javascript?
<p>I have a function like that :</p>

<pre><code>function whenEmpty(field) {
  if (field.value == '') {
     field.style.backgroundColor = "#ffcccc";
     alert("Please fill the field.");
     field.focus();
  } else {
     field.style.backgroundColor = "#ffff80";
  }
}
</code></pre>

<p>Before I thought about that idea (I want to call this function when tab key is pressed. ) I call the function on attribute onblur. </p>

<pre><code>&lt;tr&gt;
  &lt;td&gt;
    &lt;div class="required"&gt;
      &lt;label&gt;Phone&lt;/label&gt;
    &lt;/div&gt;
  &lt;/td&gt;
  &lt;td&gt;
    &lt;form:input path="connote.destPhone" id="destPhone" htmlEscape="true" onfocus="this.select();" onmouseup="return false;" onblur="whenEmpty(this);" style="background-color:#ffff80" size="20" maxlength="50" tabindex="9" /&gt;
    &lt;form:errors path="connote.destPhone" cssClass="error" /&gt;
  &lt;/td&gt;
&lt;/tr&gt;
</code></pre>

<p>But now I want call that function only when I press tab.</p>