onBlur Area Code
<p>What I am trying to do is check to see if they entered 3 numbers for Area Code and then when they enter 3 move to the next field.  3 numbers must be entered.  I have tried it several ways.</p>

<p>Updated:
I am also trying to make sure they put 3 a required 3 digits in the area code, phone prefix and 4 numbers in the  phone suffix.</p>

<p>I think I should not be using the onblur... I think... </p>

<p>Form Code:</p>

<hr>

<pre><code>            &lt;div class="formPhone" style="float:left;"&gt;
            (&lt;input name="areaCode" id="areaCode"  type="text"  maxlength="3"
                onkeyup="validateNextField(this,3,phonePrefix);" 
                onblur="validateFixedLengthNumericField(this,3);"  
                style="font-size:11px; width:20px;"  title="Area Code" autocomplete="off"&gt;) 
            &lt;input name="phonePrefix" id="phonePrefix" type="text" 
                onkeyup="validateNextField(this,3,phoneSuffix);" 
                onblur="validateFixedLengthNumericField(this,3);"  
                style="font-size:11px; width:20px;" maxlength="3"  title="Phone Prefix" autocomplete="off"&gt;-
            &lt;input name="phoneSuffix" id="phoneSuffix" type="text"  maxlength="4" 
                onkeyup="validateNextField(this,3,phoneExtension);" 
                onblur="validateFixedLengthNumericField(this,4);"  
                style="font-size:11px; width:25px;" title="Phone Suffix" autocomplete="off"&gt; 
            ext: 
            &lt;input name="phoneExtension" id="phoneExtension" type="text"  maxlength="5" 
                onkeyup="validateNextField(this,5,dsnPrefix);" 
                style="font-size:11px; width:25px;" title="Phone Extension" autocomplete="off"&gt;
        &lt;/div&gt;
</code></pre>

<p>JavaScript Code</p>

<hr>

<pre><code>function validateFixedLengthNumericField(numericField, len){

    if (len != numericField.value.length){
        numericField.focus();   
        alert('Field must contain exactly '+len+' numbers.');
    }
}

// Once the max length is reached it forwards to the next field.
function validateNextField(numericField, len, nextField){

    if (len == numericField.value.length){
        nextField.focus();
    }
}
</code></pre>
