This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

How to set a focus to an input field in method invoked after onchange() event

By: a guest on Feb 26th, 2012  |  syntax: None  |  size: 0.76 KB  |  views: 29  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <spring:message code="template.fields.label.from"/>:
  2.        <mvc:input  path="templateFields.selectorRangeFrom"
  3.        onchange="validateNumber('templateFields.selectorRangeFrom',true)"/>
  4.    <spring:message code="template.fields.label.to"/>:
  5.       <mvc:input path="templateFields.selectorRangeTo"  
  6.      onchange="validateNumber('templateFields.selectorRangeTo',true)"/>
  7.        
  8. function validateNumber(index,isInteger) {
  9.  var object = document.getElementById(index);
  10.  var value = object.value;       
  11.  if (testNumeric2(value,isInteger)==false)       {
  12.          alert('Please correct the value: ' + value);                          
  13.          object.focus();
  14.          object.select();
  15.          return false; 
  16.  }
  17. return true;   
  18.  }
  19.        
  20. if (! /** check field **/) {
  21.    /** show error **/
  22.    setTimeout((function() { object.focus() }), 0);
  23. }
clone this paste RAW Paste Data