Created
October 2, 2012 16:26
-
-
Save snowman-repos/3820705 to your computer and use it in GitHub Desktop.
JavaScript: Input with Disappearing Background Image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form name="searchform" id="search-form"> | |
<div> | |
<b>Search</b> | |
<input type="text" name="txtInput" title="Enter the terms you wish to search for." /> | |
<input type="submit" value="GO!" class="submit" style="cursor: pointer;" /> | |
</div> | |
</form> | |
<script type="text/javascript" language="javascript"> | |
(function() { | |
var id = document.getElementById('search-form'); | |
if (id && id.txtInput) { | |
var name = id.txtInput; | |
var unclicked = function() { | |
if (name.value == '') { | |
name.style.background = '#FFFFFF url(images/googbg.png) left no-repeat'; | |
} | |
}; | |
var clicked = function() { | |
name.style.background = '#ffffff'; | |
}; | |
name.onfocus = clicked; | |
name.onblur = unclicked; | |
unclicked(); | |
} | |
})(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment