Skip to content

Instantly share code, notes, and snippets.

@snowman-repos
Created October 2, 2012 16:26
Show Gist options
  • Save snowman-repos/3820705 to your computer and use it in GitHub Desktop.
Save snowman-repos/3820705 to your computer and use it in GitHub Desktop.
JavaScript: Input with Disappearing Background Image
<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