I have a form field (okay, more than one) where I would like to have the text selected when I focus/click on the text. I can't get any of the online scripts to work, though - I've tested many different ones, ranging from the simplest "select.this" onClick-event to more elaborate scripts. The only thing that seems different from when I test the scripts online, to my own pages, is the DOCTYPE - I'm running: <?xml version="1.0" encoding="utf-8" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd"> Code (markup): and I know that this sometimes can mess with the javascript execution. So, does anyone have any idea as to how I can get a simple "select_all_text_in_form_field" to work with the above mentioned DOCTYPE? The form itself can be seen here: http://www.regncon.no - it's the login-field in the upper-right corner.
Tried it - does not work. It's actually up on the page now - you can see for yourself it does not trigger anything when clicking the input field.
Well well - I found something that worked, actually: onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" Code (markup): It doesn't actually select the text, but it replaces it with nothing, which is just as good. Works perfectly for what I need it for.