I am needing help with what is probably a very easy task to complete, but I have been working on it for a while and need another pair of eyes to help me figure out the missing piece. I should know how to do this but for some reason the correct layout of the code is beyond my scope of vision. Below is one way i tried writing the code, including the html elements of the page. I have also tried using a function to perform the task.

<html>
<head>
        <title>Swapping the boxes!</title>
</head>
            <body>  <center>
    <h2>  <font color= "purple" face= "comic sans MS">
    Swap the text entered from one to the other! 
    </font>  </h2>
    <br/> <br/>


    Enter text in each box:
    <br/>
        <input type="text" id="txt1" size= "15" value= "" /> &nbsp&nbsp&nbsp <input type="text" id="txt2" size= "15" value= "" />  
        <br/>
            <input type= "button" value= "Swap Text"
        onclick = "text1= document.getElementById('txt1').value;
                    text1=parseFloat(text1);
                text2= document.getElementById('txt2').value;
                    text2=parseFloat(text2);
                document.getElementById('txt1').value= text2;
                document.getElementById('txt2').value= text1;" /> 
        </center>
   </body>
</html>

Edited 3 Years Ago by mike_2000_17: Fixed formatting

<html>
<head>
<title>Swapping the boxes!</title>
</head>
<body> <center>
<h2> <font color= "purple" face= "comic sans MS">
Swap the text entered from one to the other!
</font> </h2>
<br/> <br/>


Enter text in each box:
<br/>
<input type="text" id="txt1" size= "15" value= "" /> &nbsp&nbsp&nbsp <input type="text" id="txt2" size= "15" value= "" />
<br/>
<input type= "button" value= "Swap Text"
onclick = "swaptext(document.getElementById('txt1').value,document.getElementById('txt2').value)";/>
</center>
</body>
</html>

<script>

	function swaptext(txt1,txt2)
    {
    	document.getElementById('txt1').value = txt2;
    	document.getElementById('txt2').value = txt1;
	}
</script>

this will do what you are after

Thank you so much this worked perfectly. I was so close in one of my attempts that I didn't save. Thank you.

This question has already been answered. Start a new discussion instead.