Javascript Onclick Highlight To Select And Copy
javascript onclick highlight to select and copy
javascript, onclick, highlight, to, select, and, copy
Javascript Onclick Highlight To Select And Copy
Post Description: javascript onclick highlight to select and copy
POST# 1405
Posted On: Wed Jun 04, 2008 8:54 pm
hotsalsa
Topic: Javascript Onclick Highlight To Select And Copy
how do i enable automatic select a text field with javascript?

i mean if i have a form and i want the user to just click the field and be able to copy
Share:
BBCODE:
HTML Code:


Wed Jun 04, 2008 9:01 pm
1
Web Hosting Support
Reply #2064
you can use this code:

<script type="text/javascript">
function select_all(obj)
{ var text_val=eval(obj);
text_val.focus();
text_val.select();
if(!document.all) return; // IE only
r= text_val.createTextRange();
r.execCommand('copy');
}
</script>
<p>Text Field:
<input name="textfield" type="text" size="40" value="click here to highlight" onclick="select_all(this)">
</p>


DEMO of Code Above



Text Field:

What do you think?

* name:  

* email:  

* Please enter comments:


Receive Replies on my Comments
(An email will be sent to you when someone replies to your comments)

Add image to comments
yes no             upload