Thread: Swap textarea values
Results 1 to 2 of 2
Related
-
using javascript to update checkbox values and write output to textarea dynamically Forum: Javascript Forum
Replies: 6 -
image swap Forum: CSS Forum
Replies: 1 -
mouse swap? Forum: HTML Forum
Replies: 1
-
01-05-2005, 11:14 AM #1
Swap textarea values
What would be the best way to swap the contents of two text areas?
I have the following attached to a text link:
onclick="document.forms[0].heading1.value=document.forms[0].heading2.value;document.forms[0].heading2.value=document.forms[0].heading1.value"
But it only changes heading1 to the value of heading2. How can I swap them?
Many thanks.
-
01-05-2005, 04:32 PM #2bald headed old fart
Status- Offline
Join Date- Aug 2003
Location- chertsey, a small town 25 miles south west of london, england.
Posts- 739
Hi there shaunbrazier,
and a warm welcome to these forums
Actually, it is working
This is what is taking place....
Let's call the two values...'a' and 'b'
onclick replaces value 'a' with that of 'b'
value 'a' now no longer exists so value 'b'
is then replaced with.......value 'b'.
To overcome this problem this value 'a'
needs to be stored prior to the first swap
and it can then be called for the second.
Here is the script that does this, it employs another variable to store value 'a'.
Code:<script type="text/javascript"> <!-- function swapAreaText() { var df=document.forms[0]; var area1=df[0].value; var area2=df[1].value; var store=area1; df[0].value=area2; df[1].value=store; //--> } </script> <form action="#"> <div> <textarea rows="3" cols="13">this is textarea one well it is until the link is clicked</textarea> <textarea rows="3" cols="13">and this is textarea two</textarea> </div> </form> <a href="javascript:void(swapAreaText())">this is a link</a>
Cloudjiffy- PaaS for Developers
10-05-2020, 12:30 AM in Web Hosting Forum