Click to See Complete Forum and Search --> : Select all in div


IxxI
03-13-2003, 02:34 AM
What would the code be to select all the text in a div box? I've written a code generator that displays its output in a div box, I was just wondering how one could use a button to select all of the text, or better still copy it to clipboard,
Thanks,
IxxI

khalidali63
03-13-2003, 05:16 AM
Here is one way of doing it crude but easy..

:D

<div onclick="alert(this.innerHTML)" > This is a div<br/> and I intend to select<br/>
all data by clicking on it.</div>

Ceers
Khalid

IxxI
03-13-2003, 06:41 AM
Thanks Khalid,
however unfortunately as it is a code generator the innerHTML is different to what is shown on screen as it is changed by what the user has written in a form. Any other ideas?
IxxI

khalidali63
03-13-2003, 06:55 AM
ok..you want to select all from the webpage using user mouse(drag or double click)?

true?

Khalid

IxxI
03-13-2003, 07:08 AM
No, sorry. It generates code on the same webpage. However I've found a different way to do it - I'm outputting it into a textbox so I'm using document.form.textbox.select() to select the code. My question is how do I make the code appear on different lines? Because I'm using document.form.textbox.value=code (as opposed to innerHTML with a div) I can't use <br> as it just writes that into the textbox. Is there anyway of including a line break in my variables so that it outputs the code on four different lines? I think I might have seen it done somewhere using document.writeln but I can't work out where or how to use it,
Thanks again,
IxxI

pyro
03-13-2003, 07:14 AM
In a textarea, \n gives you a new line...

khalidali63
03-13-2003, 07:25 AM
I guess that solves it..:-)

Khalid

IxxI
03-13-2003, 07:35 AM
Thank you both - much obliged for your efforts (or non-efforts as the case may have been ;) ).
IxxI