Jump to content

Textbox Background Swap


ferdia

Recommended Posts

Hi guys, simple one for you. I have two text boxes that I want to change the background image of, onFocus.

 

Here is the text boxes:

<td><input type="text" name="user" maxlength="30" value="" id="userbox"></td>
<td><input type="password" name="pass" maxlength="30" value="" id="passbox"></td>

 

And here is the CSS that adds the background images:

#userbox {
background-image:url('../images/username.png');
background-repeat:no-repeat;
}

#passbox {
background-image:url('../images/password.png');
background-repeat:no-repeat;
}

 

Any ideas on how I would switch the backgrounds to another image? Lets say blank.png?

 

Thanks in adance.

Link to comment
Share on other sites

try this: 

<td>
     <input onfocus = "this.style.background = 'url(blank.png)'" onblur = "this.style.background = 'url(original.png)'" type="text" name="user" maxlength="30" value="" id="userbox">
</td>
<td>
     <input onfocus = "this.style.background = 'url(blank.png)'" onblur = "this.style.background = 'url(original.png)'" type="password" name="pass" maxlength="30" value="" id="passbox">
</td>

Link to comment
Share on other sites

 

<td>

    <input onfocus = "this.style.background = 'url(blank.png) no-repeat'" onblur = "this.style.background = 'url(original.png) no-repeat'" type="text" name="user" maxlength="30" value="" id="userbox">

</td>

<td>

    <input onfocus = "this.style.background = 'url(blank.png) no-repeat'" onblur = "this.style.background = 'url(original.png) no-repeat'" type="password" name="pass" maxlength="30" value="" id="passbox">

</td>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.