javascript onclick select all text in a form field

Mobile
feeds
Welcome Login | Register

javascript onclick select all text in a form field
Reply Your Comments:
Click this button if you are interested in replying to this topic and leave your comments
Sent To Friend
CLick this button if you want to send this page to a friend.
Subsribe To Rss Feeds
Subscribe to RSS
CLick this button if you want to subscribe to this RSS Feed. You can use your browsers feeds burners if you have mozilla or internet explorer 7 or higher and keep up with updates.
  Forums Index
      » Javascipt Forums
        » » javascript onclick select all text in a form field
javascript onclick select all text in a form field
Post Description: javascript onclick select all text in a form field Javascipt
Post Tags:
This Post Has Been Viewed 886 Times Since Wed Sep 24, 2008 11:22 am Author hostman with 5 replies
javascript onclick select all text in a form field
Advertise On This Page




onClick="select_text();"

ok. lets say i have a field, and as soon as you click on that field, you want all the text contained within the field to be selected automatically. well, you can do that with javascritp on this tutorial i will show you how you can do that.

here is the demonstration example
and here is the code i used:
<script type="text/javascript">
function select_text()
{
var content=eval("document.myform.field");
content.focus();
content.select();
}
</script>
<form method="post" action="" name="myform" >
<textarea name="field" rows="4" cols="40" onClick="select_text();">Click Inside the text area to select all
  text within this form field </textarea>
</form>


hope you learned something from this short and useful tutorial

courtesy of www.webune.com


Leave Your Comments

Your Name
Your Email Address (Will Not Be Published)
Notify Me When Someone Replies to this Page
(An email will be sent to you when someone replies to your comments)
Your Comments
Include A Picture with your comments
Share
| More
Share this page by putting this URL in your comments to other websites like myspace, Facebook, Twitter friendster, Hi5, Groups, Boards, Forum or others. Just Copy and Paste this Code
URL:
To embed this topic, just copy the code from the "Embed" box. Once you've copied the code, just paste it into your website or blog to embed it.
Embed:
BBCODE is use on forums. You can put this code on all your BBCODE enabled forums like PhpBB, vBulletin® and others. Just Copy and Paste this code on your Posts and Replies on your forums
BBCODE:
Subscribe Feeds
Webmasters - Exchange Links With Us. Add related websites to this topic
Add Link:
Links Related to : javascript onclick select all text in a form field

Comments and replies About javascript onclick select all text in a form field
:: 1 :: Reply #83824 Reply By wallpaperama On Fri Nov 28, 2008 11:06 am
wallpaperama:
another way you can do this:

follow my steps:

1. i am using windows xp, so open a blank notepad.

2. copy and past this code into the blank notepad:
<form action="" name="wallpaperamaFrom" id="wallpaperamaFrom">
Wallpaperama: <input name="myurl" id="url-field" type="text" value="http://www.wallpaperama.com/" onClick="javascript:document.wallpaperamaFrom.myurl.focus();document.wallpaperamaFrom.myurl.select();" readonly>
</form>


3. now save it as wallpaperama.html

4. after you have saved it, open it with your browswer, you will see it works


DEMO:


Wallpaperama URL:
:: 2 :: Reply #86631 Reply By Bas On Thu Dec 18, 2008 2:01 am
Bas:
how can i get this script to work on all the fields in my form?
:: 3 :: Reply #91509 Reply By jackie On Sun Jan 25, 2009 9:01 pm
jackie:
i have firefox i tested on firefox but i dont think it works on internet explorer
:: 4 :: Reply #122921 Reply By Ali On Wed Dec 09, 2009 11:36 pm
Ali:
10-6378-vampire.jpg
thanks,
its working for me too

regards ali arshad.
:: 5 :: Reply #126777 Reply By DCD On Tue Jan 26, 2010 4:16 pm
DCD:
It may not be W3C, but just using the onClick="javascript:focus within the form field as an attribute works. Firefox 3.5.