title: Comparing two input fields
body: <p>I have this function which i am using to compare two input fields. If the user enters the same number in both the text field. On submit there will be an error. Now i would like to know if there is a way to allow same number but not higher than or lower the value of the previous text box by 1. For example if user enters 5 in previous text box, the user can only input either 4, 5 or 6 in the other input field.Please give me some suggestions.</p>
  
  <pre><code>   &lt;script type="text/javascript"&gt;
  function Validate(objForm) {
  var arrNames=new Array("text1", "text2");
  var arrValues=new Array();
  for (var i=0; i&lt;arrNames.length; i++) {
  var curValue = objForm.elements[arrNames[i]].value;
  if (arrValues[curValue + 2]) {
  alert("can't have duplicate!");
  return false;
  }
  arrValues[curValue] = arrNames[i];
  }
  return true;
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>
  </p>
  
  <pre><code>&lt;form onsubmit="return Validate(this);"&gt;
  &lt;input type="text" name="text1" /&gt;&lt;input type="text" name="text2" /&gt;&lt;button type="submit"&gt;Submit&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p></p>