Click to See Complete Forum and Search --> : Copy highlighted text from one text box to another


sonyb
07-07-2003, 06:24 PM
Hi,

Does anyone know how can I copy the highlighted text from one text box to another.As soon as I highlight the text I it should be copied to a different text box. :confused:

freefall
07-07-2003, 07:33 PM
I can't tell you how much crap I went through on MSDN to find out how to do this, wow! Utilizes the document.selection (which I didnt know existed) object to find out what's selected, then create a text range (which I didnt know existed) from it and find out what's in the text range using the text property (which I didn't know existed). But I think it's exactly what you wanted, so it's worth it!
<script type="text/javascript">
function pasteText()
{
var selected = document.selection.createRange();
document.forms[0].paste.value = selected.text;
}
</script>
<form>
Type here: <input type="text" name="copy" onselect="pasteText();"><br><br>
Selected: <input type="text" name="paste">
</form>
Cheers!!
- Ian Paterson

sonyb
07-08-2003, 03:02 PM
Thanks a tonn. Also I saw your website degreethreedesigns .. Its neat.. the way you have done the browser capabilities on the top bar ..

Anyways coming back to the solution. Yup this is what I want to do more or less ..but when the text is written in a multiline textbox, I have to write down line numbers and then get the word that is highlighted along with the line number it was highlighted from. But I think i will work on it and get some out put...

Once Again .. Thanks a tonn for your help.:)

sonyb
07-09-2003, 03:34 PM
Hi Guys,

Need some help ... I have this multiline text box (textbox A)in which I am copying some text. Now First thing I need is to get row numbers on the left of each line I have copied in this text box A . Then when I highlight the text in this text box A Another text box (say text box B) gets filled with the highlighted text. However If I select another text from textbox A the text that was in textboxB gets overwritten.. However I want that a new text box gets created when I highlight another text ..

Please If someone could help .. The code for highlighting the text and copying it on another text box is already there ..
see If u guys could help me with this..

Would really appreicate it.

Thanks
:(