javascript validation for ordering of numbers
<p>The following code is to check validation for numbers.num1,num2 and num3. The validation works like num1 is less than num2 is less than num3. This order it will follow and it is working, but after displaying the alert message the number which is entered and breaks the order needs to be reset to empty.</p>

<pre><code>&lt;form name="validateForm" method="POST"&gt;Enter num1
    &lt;input type="text" id="num1" name="num1" value="" onchange="javascript:validate()" /&gt;
    &lt;br/&gt;Enter num2
    &lt;input type="text" id="num2" name="num2" value="" onchange="javascript:validate()" /&gt;
    &lt;br/&gt;Enter num3
    &lt;input type="text" id="num3" name="num3" value="" onchange="javascript:validate()" /&gt;
    &lt;br/&gt;
&lt;/form&gt;
</code></pre>

<p>Code: </p>

<pre><code>function validate() {
    var num1 = document.validateForm.num1.value;
    var num2 = document.validateForm.num2.value;
    var num3 = document.validateForm.num3.value;
    var count = 0;
    if (num1 != "") {
        count++
    }
    if (num2 != "") {
        count++
    }
    if (num3 != "") {
        count++
    }
    var numarray = new Array(count);
    var flag = "false";
    var j = 0;
    if (!isNaN(num1)) {
        numarray[j] = num1;
    } else {
        flag = "true";
    }


    if (!isNaN(num2)) {
        if (flag == "true") {
            alert("numbers are not in order");
            document.validateForm.num2.value = "";
            return false;
        }
        numarray[j] = num2;
        j++;
    } else {
        flag = "true";
    }
    if (!isNaN(num3)) {
        if (flag == "true") {
            alert("numbers are not in order");
            document.validateForm.num3.value = "";
            return false;
        }
        numarray[j] = num3;
        j++;
    }
    if (numarray.length &gt; 1) {
        for (var x = 0; x &lt; numarray.length - 1; x++) {
            if (numarray[x + 1] &lt; numarray[x]) {
                alert("numbers are not in order");
                return false;
            }
        }
    }
}  
</code></pre>
