...

View Full Version : Auto Highlighting Code



cyphix
05-28-2004, 05:00 PM
I've seen these buttons around the net where the user has to copy code in a window but instead of selecting all the code themselves with their mouse they can instead click a button under the code window that says something like "Highlight Code" & then all the code in the window is highlighted & they can eaisly copy it...

How can you do this?

Thanks!

swmr
05-28-2004, 05:52 PM
document.formName.elementName.select()

cyphix
05-28-2004, 07:55 PM
So where do I put that code?

Willy Duitt
05-28-2004, 08:47 PM
<form><textarea name="textarea" cols="42" rows="12">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec nibh lorem, pellentesque eget, gravida quis, hendrerit sit amet, elit. In molestie faucibus nunc. Suspendisse potenti. Cras eros odio, tincidunt at, iaculis non, tempor nec, dui. Pellentesque massa erat, adipiscing at, tempor nec, condimentum sit amet, magna. Vestibulum porttitor felis at quam. Nulla vel libero non ipsum tristique adipiscing. Maecenas consequat pretium ante. Vestibulum porta. Mauris congue velit vitae augue. Ut facilisis posuere erat. Aliquam interdum porta erat</textarea><br>
<input type="button" value="Select"
onclick="this.form.textarea.focus();
this.form.textarea.select()"></form>

cyphix
05-28-2004, 09:13 PM
Thanks! :D

swmr
05-28-2004, 09:57 PM
Just the select() would probably do.

Setting focus() doesn't seem necessary. ;)

Willy Duitt
05-28-2004, 10:09 PM
For most instances you are probably right but for those times that the text to be highlighted is not currently in the viewport, setting focus would be better. Below is a brief example. If you try it with and without focus you will see the differences.


<form>
<div style="height:1800px">
<input type="button" value="Select"
onclick="this.form.textarea.focus();this.form.textarea.select()"></div>


<textarea name="textarea" cols="42" rows="12">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec nibh lorem, pellentesque eget, gravida quis, hendrerit sit amet, elit. In molestie faucibus nunc. Suspendisse potenti. Cras eros odio, tincidunt at, iaculis non, tempor nec, dui. Pellentesque massa erat, adipiscing at, tempor nec, condimentum sit amet, magna. Vestibulum porttitor felis at quam. Nulla vel libero non ipsum tristique adipiscing. Maecenas consequat pretium ante. Vestibulum porta. Mauris congue velit vitae augue. Ut facilisis posuere erat. Aliquam interdum porta erat</textarea><br>
</form>

swmr
05-28-2004, 10:28 PM
Good point. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum