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.
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.
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.
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 http://www.recommendedtradesmen.co.uk, 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:
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
document.srch.location.select(); //**highlight the text
}
//–>
Usage:
We use an OnBlur event for the specified field:
onBlur=”testPostCode();”
This then bypasses the issues previously noted in FF/NS.
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…
Juli 27, 2006 pukul 5:34 pm
Hi,
The simple provided by u was very helpful to us. We were looking for the same functionality. Thanks again for the timely help.
Regards
Amol
Juli 27, 2006 pukul 5:35 pm
Hi,
The simple tip provided by u was very helpful to us. We were looking for the same functionality. Thanks again for the timely help.
Regards
Amol
Juli 28, 2006 pukul 8:53 am
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.
Regards,
Arief
Juli 28, 2006 pukul 11:45 am
Hi,
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?
Jeff
Juli 28, 2006 pukul 2:58 pm
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.
Thanks
Arief
Oktober 4, 2006 pukul 10:39 am
Wah laris laris
Desember 29, 2006 pukul 2:21 pm
Hi all,
Please let me know the differences b/n form.textbox.select() and form.textbox.focus().
Desember 29, 2006 pukul 3:27 pm
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.
Januari 1, 2007 pukul 4:44 pm
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 http://www.recommendedtradesmen.co.uk, 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:
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
document.srch.location.select(); //**highlight the text
}
//–>
Usage:
We use an OnBlur event for the specified field:
onBlur=”testPostCode();”
This then bypasses the issues previously noted in FF/NS.
Hope this helps.
Januari 31, 2007 pukul 2:52 pm
Dear Friends
i want to create when curson jomp on different textbox,
i want highlite active textbox
can u help me Please?
Februari 2, 2007 pukul 1:14 pm
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.
Maret 22, 2007 pukul 9:36 am
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…
Januari 1, 2008 pukul 2:16 pm
The solution is easy folks. Just use the onmouseup event on the said text field:
<input type=”text” onmouseup=”this.select()”>
Januari 17, 2009 pukul 10:25 pm
[url=http://couplewhrcoupl.tripod.com/qbame/hot-buckwild-fucking.htm]hot buckwild fucking[/url]