# Javascript - swapping text box values

**URL:** <https://forum.kirupa.com/t/javascript-swapping-text-box-values/164071>\
**Category:** web dev\
**Created:** [September 28, 2005, 10:57am UTC](https://forum.kirupa.com/t/javascript-swapping-text-box-values/164071 "2005-09-28T10:57:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oli\_G](https://avatars.discourse-cdn.com/v4/letter/o/f05b48/32.png) [@Oli\_G](https://forum.kirupa.com/u/Oli_G)\
**Post date:** [September 28, 2005, 10:57am UTC](https://forum.kirupa.com/t/javascript-swapping-text-box-values/164071/1 "2005-09-28T10:57:48Z")

</div>

Hi all

I have two textboxes, whereby the contents are swapped to be in numerical order.

I have this working but need to add a third text box, but can’t figure out how… I tried some long winded extra if statements, but to no avail.

```auto

function swapVals() {

	f1Obj = document.getElementById('f1');
	f2Obj = document.getElementById('f2');
if(Number(f1Obj.value)>Number(f2Obj.value)){
var temp = f2Obj.value;
f2Obj.value=f1Obj.value;
f1Obj.value = temp;
}

} 

```
