Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy Textbox to multiple fields via button 1

Status
Not open for further replies.

cfcProgrammer

Programmer
Mar 1, 2006
88
CA
Hi

I'm looking to copy from one field to another via a button using the code below. But I want the button to copy to more than one field. i.e. copy text from field1 to field2 and field3.

<button onclick="document.getElementById('field2').value=document.getElementById('field1').value">Copy Text</button>

Thanks!

cfcProgrammer
 
This is basically javascript not hTMl however, you can just keep adding as many fields as you need:L

Code:
<button onclick="document.getElementById('field2').value=document.getElementById('field1').value[red];[/red][blue]onclick="document.getElementById('field3').value=document.getElementById('field1').value[/blue][red];[/red][blue]onclick="document.getElementById('field4').value=document.getElementById('field1').value[/blue]; ">Copy Text</button>


Fro any further Javascript question you can post in the forum216


----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
ignore that, copy and paste issues:

Code:
<button onclick="document.getElementById('field2').value=document.getElementById('field1').value[red];[/red]
document.getElementById('field3').value=document.getElementById('field1').value[red];[/red]document.getElementById('field4').value=document.getElementById('field1').value[red];[/red] ">Copy Text</button>



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Hi

An old habit since the early implementations of [tt]getElementById()[/tt] when it was quite slow in some browsers. I used to reduce the number of such calls.
Code:
<button onclick="document.getElementById('field2').value = document.getElementById('field3').value = document.getElementById('field4').value = document.getElementById('field1').value">Copy Text</button>

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top