Created
August 27, 2015 23:56
-
-
Save jordanneenan/00fdf984019c14bc655e to your computer and use it in GitHub Desktop.
Control default text in a field
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
//Field text - remove on focus, replace on blur | |
function fieldText(){ | |
var $fieldText = jQuery('.js-text'); | |
$fieldText.focus(function(){ | |
var fText = jQuery(this).data("fieldtext"); | |
var fVal = jQuery(this).val(); | |
if(fVal === fText){ | |
jQuery(this).val(""); | |
} | |
}) | |
$fieldText.blur(function(){ | |
var fText = jQuery(this).data("fieldtext"); | |
var fVal = jQuery(this).val(); | |
if(fVal === ""){ | |
jQuery(this).val(fText); | |
} | |
}) | |
} |
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
<input class="js-text" type="text" data-fieldtext="$searchText" value="$searchText" name="s" id="s" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment