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: