Wednesday, October 28, 2009

JavaScript : Onclick Event - Copy text

The text in the first input field will be copied to the second input field when a button is clicked:

Demo :
Click the button to copy the content of Field1 to Field2.

Field1:
Field2:


Sample Code :
Click the button below to copy the content of Field1 to Field2.
<br />
Field1: <input type="text" id="field1" value="Hello World!">
Field2: <input type="text" id="field2">
<button onclick="document.getElementById('field2').value=
document.getElementById('field1').value">Copy Text</button>

1 comment:

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Front end developer learn from Javascript Training in Chennai . or learn thru JavaScript Online Training in India. Nowadays JavaScript has tons of job opportunities on various vertical industry. JavaScript Training in Chennai

    ReplyDelete