Call javascript function on maxlength of textfield
<p>I am looking for a script that calls for a JavaScript function automatically when reaching the maxlength of a text field.</p>

<p>I tried to modify this piece of Script which I found here <a href="http://stackoverflow.com/questions/11801672/ajax-call-after-x-characters">ajax call after x characters</a></p>

<pre><code>$("input#zipcode").live("keyup", function( event ){
    if(this.value.length == this.getAttribute('maxlength')) {
        if(!$(this).data('triggered')) {
            // set the 'triggered' data attribute to true
            $(this).data('triggered',true); 
            if ($(this).valid() == true ) { loadXMLDoc(); } 
        }
    } else { $(this).data('triggered',false); }
});
</code></pre>

<p>This is the part of code containing the loadXMLDoc part:</p>

<pre><code>function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4)
    {
    document.getElementById("state_insert").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","state_insert.asp?zipcode="+document.getElementById('zipcode').value,true);
xmlhttp.send();
}
</code></pre>

<p>When the maxlength is reached, I want it to call for a "LoadXMLDoc" function which requires no additional parameters to be passed on.</p>

<p>At the moment I have it set to onblur="LoadXMLDoc()" 
Like this:</p>

<pre>[input name='zipcode' type='text' class="form_elements" id='zipcode' tabindex='11' autocomplete='off' onchange="this.value=extractNumeric(this.value)" onkeypress="return isNumericKey(event)"  value='' size="4" maxlength="5" onblur="loadXMLDoc()" /]</pre>

<p>I used the [ and ] because &lt; and > are not allowed.</p>

<p>in the text field properties, but I would like that it loads as soon as the 5 digits of the Zip Code have been entered.</p>

<p>Thanks in advance :)</p>

<pre><code>Robert.
</code></pre>
