Jump to content

Auto Add Function


driz

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...