Javascript: Highlight All Text In Textfield On Focus

This post has been moved. Click here.


15 Tanggapan to “Javascript: Highlight All Text In Textfield On Focus”

  1. Amol Tajave Says:

    The simple provided by u was very helpful to us. We were looking for the same functionality. Thanks again for the timely help.


  2. Amol Tajave Says:

    The simple tip provided by u was very helpful to us. We were looking for the same functionality. Thanks again for the timely help.


  3. Arief Fajar Nursyamsu Says:

    Hi Amol,

    It is glad to know that this simple tip is useful for others. Some are came here by search engine and this post is the most popular post over my blog.
    Thanks for visiting and commenting.



  4. Jeff Bush Says:


    This is a very nice little script. It works very well in Internet Explorer, but breaks slightly in mozilla-type browsers (new Netscapes and Firefox) and possibly others. Ths problem comes up if the user does a slowish click, the mouse-up event is fired after the focus event and the text is deselected as the cursor is placed during mouse-up (IE places cursor during mouse-down which is why it works).

    You can’t just replace the onMouseUp/onClick event because then the user would never be able to click a part of the text to move the cursor.

    Any ideas?


  5. Arief Fajar Nursyamsu Says:

    Hi Jeff,

    I have no idea about this. At the time I wrote this post, I tested it with IE only. Once I have a solution, I’ll post it here.
    Or, just let me know if you find the solution first.



  6. Jauhari Says:

    Wah laris laris 😉

  7. Prashanth Devaki Nanjappa Says:

    Hi all,

    Please let me know the differences b/n and form.textbox.focus().

  8. Arief Fajar Nursyamsu Says:

    Hi Prashanth, thanks for visiting.

    The difference is on the fact that select() will highlight all text inside textbox, but focus() will set your cursor to related textbox.

  9. mark lawson Says:

    Hi all,

    Thanks for the snippet, I have found that deploying the select() functionality within a separate function works just fine. For example on our website at, we have a postcode search which filters out city names and alerts the user, so I added in the additional elements into the function (which used an alert msgbox previously)

    function testPostCode () {
    var myPostCode = document.getElementById(‘location’).value;
    if (checkPostCode (myPostCode)) {
    document.getElementById(‘location’).value = checkPostCode (myPostCode)
    //alert (“Postcode has a valid format”)
    return true; //subbed this instead of the alert box
    else {alert (“Invalid postcode format\nplease retry with a postcode\nsuch as EH14 5ET.”)};
    document.srch.location.focus(); //**place the cursor in the field; //**highlight the text

    We use an OnBlur event for the specified field:


    This then bypasses the issues previously noted in FF/NS.

    Hope this helps.

  10. paras Says:

    Dear Friends
    i want to create when curson jomp on different textbox,
    i want highlite active textbox

    can u help me Please?

  11. Arief Fajar Nursyamsu Says:

    Hi Paras,

    So you want to highlight the textbox not the textbox. You may use a CSS to do that and trigger it with onFocus() event.

  12. Rasito Says:

    Beberapa orang programer amerika saat berhasil membuat satu bahasa program, agak bingung memberikan nama. Salah satu dari mereka teringat pengalaman mereka waktu ke jalan-jalan ke P. jawa, mereka melihat pemandangan orang yang duduk-duduk santai sambil minum kopi. Ingatan tersebut menjadikan mereka sepakat memberikan nama pada bahasa program teruan mereka yaitu “javascript” dengan lambang “secangkir kopi yang masih mengepulkan aroma sedapnya”

    dan Kita juga harusnya bisa bikin donk….bukan hanya jadi nama saja….selamat buat yang mau mencobanya…

  13. The Wizard Says:

    The solution is easy folks. Just use the onmouseup event on the said text field:

    <input type=”text” onmouseup=””>

  14. onglinaxgp Says:

    [url=]hot buckwild fucking[/url]

  15. JamesGames Says:

    i’m so thrilled that i saw this page. that comment was so great. thanks again i saved this page.
    are you going to post similar news?

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:


You are commenting using your account. Logout /  Ubah )

Foto Google+

You are commenting using your Google+ account. Logout /  Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout /  Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout /  Ubah )


Connecting to %s

%d blogger menyukai ini: