driz Posted June 3, 2009 Share Posted June 3, 2009 Is it possible to add this: onFocus="clearText(this)" onBlur="clearText(this)" to an input field WITHOUT actually adding it manually?So for example if I had this: <input type="text" /> I could STILL have the onFocus and onBlur on that text box by using JS to add them instead. Link to comment Share on other sites More sharing options...
justsomeguy Posted June 3, 2009 Share Posted June 3, 2009 You can attach events using Javascript. You can use getElementById to get a single element, or getElementsByTagName to get all input elements, for example. For each element you can attach the focus and blur handlers. document.getElementById("search").onfocus = function() { clearText(document.getElementById("search")); }; Link to comment Share on other sites More sharing options...
inktherapy Posted June 4, 2009 Share Posted June 4, 2009 Like what justsomeguy mentioned, you can also put it on a function (like a listener) on blur or on focus will trigger the specific methods. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.