title: Reverse the order of an auto date format
body: <p>The function I am using formats inserts '-' at certain points to auto format the date field. Right now it prints in the format 'mm-dd-yyyy', I am trying to get it to print 'yyy-mm-dd'.  </p>
  
  <pre><code>  &lt;input type=textbox id=date onkeyup="dtval(this,event)" /&gt;
  </code></pre>
  
  <p>the js</p>
  
  <pre><code>  function dtval(d,e) {
    var pK = e ? e.which : window.event.keyCode;
      if (pK == 8) {d.value = substr(0,d.value.length-1); return;}
    var dt = d.value;
    var da = dt.split('-');
      for (var a = 0; a &lt; da.length; a++) {if (da[a] != +da[a]) da[a] = da[a].substr(0,da[a].length-1);}
         if (da[0] &gt; 31) {da[1] = da[0].substr(da[0].length-1,1);da[0] = '0'+da[0].substr(0,da[0].length-1);}
         if (da[1] &gt; 12) {da[2] = da[1].substr(da[1].length-1,1);da[1] = '0'+da[1].substr(0,da[1].length-1);}
         if (da[2] &gt; 9999) da[1] = da[2].substr(0,da[2].length-1);
      dt = da.join('-');
        if (dt.length == 2 || dt.length == 5) dt += '-';
      d.value = dt;
   }
  </code></pre>