I'm wanting to change an input field's color when you click on it, and then reset it back to normal if you click outside of it. Would anybody be able to tell me or point me in the way of an article?
Thanks much.
| SitePoint Sponsor |




I'm wanting to change an input field's color when you click on it, and then reset it back to normal if you click outside of it. Would anybody be able to tell me or point me in the way of an article?
Thanks much.

Try this to change the color of the input field...
I would use css classes if I were you. If using "this" as an input into the function doesn't work, you could suppy the input id instead and change its properties with getElementById in javascript.Code:<input type="text" id="fmName" onfocus="chgBgColor(this") onblur="resetBgColor(this)" /> <script type="text/javascript"> <!-- function chgBgColor(objInput) { objInput.style = "background-color: red"; // or you could set objInput.className to a css class instead } function resetBgColor(objInput) { objInput.style = ""; // or you could set objInput.className to a css class instead } //--> </script>




Thanks much, that did it for me.

Good stuff!
Bookmarks