...

View Full Version : button onclick copy the text in textarea



mrjameer
07-05-2007, 01:27 PM
hi,

i have 3 textareas and 3 buttons on a page.when i click the particular button the text inside the textarea should be copied.it is working but when i keep this in a for loop,it is not working

iam using the following code.but when i click button and paste the text it displays 'undefined'.not copyin the text.any of your help will be appreciated
thanks
mrjameer

<?php
for($i=0;$i<=3;$i++)
{
?>
<textarea name="copytext1">ABCD</textarea><BUTTON onClick="ClipBoard1();">Copy to Clipboard</BUTTON> <br>
<textarea name="copytext2">EFGH</textarea><BUTTON onClick="ClipBoard2();">Copy to Clipboard</BUTTON> <br>
<textarea name="copytext3">IJKL</textarea><BUTTON onClick="ClipBoard3();">Copy to Clipboard</BUTTON> <br>

<?php
}
?>


<TEXTAREA ID="holdtext" STYLE="display:none;">
</TEXTAREA>


<SCRIPT LANGUAGE="JavaScript">

function ClipBoard1()
{
holdtext.innerText = copytext1.innerText;
Copied = holdtext.createTextRange();
Copied.execCommand("Copy");
}
function ClipBoard2()
{
holdtext.innerText = copytext2.innerText;
Copied = holdtext.createTextRange();
Copied.execCommand("Copy");
}
function ClipBoard3()
{
holdtext.innerText = copytext3.innerText;
Copied = holdtext.createTextRange();
Copied.execCommand("Copy");
}
</SCRIPT>

abduraooft
07-05-2007, 01:46 PM
lol,

putting the code


<textarea name="copytext1">ABCD</textarea><BUTTON onClick="ClipBoard1();">Copy to Clipboard</BUTTON> <br>
<textarea name="copytext2">EFGH</textarea><BUTTON onClick="ClipBoard2();">Copy to Clipboard</BUTTON> <br>
<textarea name="copytext3">IJKL</textarea><BUTTON onClick="ClipBoard3();">Copy to Clipboard</BUTTON> <br>

means your final document would have 12 such textareas, duplicated their names
4 times, you are not allowed to do so. isn't it?
Try to validate your final page source using w3validator
:thumbsup:
regards,
art



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum