Form Input Numbers Sorted

[Total: 0    Average: 0/5]

This will order the input boxes from smallest to greatest.

Head Code:

<script>
function swap()
{
  var form=document.switchtext;
  var t1=form.text1; var v1=parseFloat(t1.value);
  var t2=form.text2; var v2=parseFloat(t2.value);
  if (v1 > v2)
  {
    var temp = t1.value;
    t1.value = t2.value;
    t2.value=temp;
  }
}
</script>

Body Code:

Please insert only numeric values.<BR />
<form name="switchtext">
<input type="text" name="text1"> <BR />
<input type="text" name="text2"> <BR />
<input type="button" name="switch" value="Switch Text" onclick=swap()>
</form>

Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *