Thursday, June 17, 2010

Javascript: Highlight all text by clicking textfield or textarea



Input TextBox:


The script is really very simple. Text field must have unique identifier, this indentifier will be passed to the SelectAll() function. The function call only two methods: focus() and select().

<script type="text/javascript">
function SelectAll(id)

<textarea rows="3" id="txtarea" onClick="SelectAll('txtarea');" style="width:200px" >This text you can select all by clicking here </textarea>

Input TextBox:<br>
<input type="text" id="txtfld" onClick="SelectAll('txtfld');" style="width:200px" value = "This text you can select all" />

If you find this useful, would you like to buy me a drink? No matter more or less, it will be an encouragement for me to go further. Thanks in advance!! =)

1 comment:

  1. You are so cool! I don't suppose I've read a single thing like this before. So nice to discover somebody with some unique thoughts on this subject. Really.. many thanks for starting this up. This web site is one thing that's needed on the web, someone with some originality!
    Digital Marketing Training In India