Hi bud
This should help you out with what you want, but if it was me I would change the className rather than changing the background colour but I don’t want to butcher your code too much.
I have added the argument id to your changeBackground function which is the id of the element you want to change the background colour of
Code:
function changeBackground(id)
{
document.getElementById(id).style.backgroundColor="#FFFFe0";
}
function checkBackground(id,val)
{
if (val=="")
{
document.getElementById(id).style.backgroundColor="#ffaaaa";
}
else
{
document.getElementById(id).style.backgroundColor="#e6e8e9";
}
}
And I have added the arguments id and val to your checkBackground function the id is the id of the element you want to change the background colour of and the val is the value of the input element
Code:
<input type="text" name="firstNameInput" onfocus="changeBackground('name1')" onblur="checkBackground('name1',this.value)">
<input type="text" name="surNameInput" onfocus="changeBackground('name2')" onblur="checkBackground('name2',this.value)">
Hope this helps
V
Bookmarks