How can I make an <input> (text) select the entire contents once it is focused? Also, I will be dynamically adding more <input>'s within the DOM so it needs to work with those too.. I'm stumped, apart from "manually" applying it to each and every element.
function select_text(object) { object.focus(); object.select(); } Code (markup): <input type="text" onclick="select_text(this);" /> Code (markup):
Is there some way to automatically apply that onclick to every input on the page, including future-created elements?
Or you can do without making any function just in the same INPUT tag. <input type="text" [COLOR="Red"]onclick[/COLOR]="javascript:this.select();" /> Code (markup):
I know that. That's extremely basic, and somebody already pointed out the onclick event... I was wondering if there was some way to automatically listen to every input box..
for(var i=0; i<document.getElementsByTagName('input').length; i++) { if(document.getElementsByTagName('input')[i].type == "text") { document.getElementsByTagName('input')[i].onfocus = function() { this.select(); } } } Code (markup):
Ya, that was how I was going to do it, but then I run into the issue of newly-created input boxes. I guess there isn't away to just automatically attach an onclick event to it...
You can set an attribute directly when you create the new ones. Could you post the code you use to create new ones?