Hi,
I'm trying to clear the contents of an input box onfocus, but without any inline javascript whatsoever. Is this possible? So far I have the following:
main.js:
index.htm:Code:window.onload = function() { clearInput('username'); } function clearInput(inputName) { if (document.getElementById(inputName).value) == inputName { document.getElementById(inputName).value = ''; } }
Code:<html> <head> <script type="text/JavaScript" src="main.js"></script> </head> <body> <form> <input type="text" name="username" value="username"> <input type="text" name="password" value="password"> </form> </body> </html>
Obviously this doesn't work because it just sets the value of the username text input to '' when the page loads. I need it only to do this once the user focuses the input box.
I guess what I'm asking is can an external javascript recognise when an element is focused without adding an "onfocus" behaviour to the HTML element? If so, how?
Thanks guys...




Bookmarks