Skip to content

Instantly share code, notes, and snippets.

@bitneek
Created February 9, 2011 00:08
Show Gist options
  • Save bitneek/817589 to your computer and use it in GitHub Desktop.
Save bitneek/817589 to your computer and use it in GitHub Desktop.
<script>
jQuery(document).ready(function() {
var hints = {
"email": "Enter your email",
"first_name": "Enter you name"
};
var hideHint = function(field, text){
if (jQuery(field).val() === text) {
jQuery(field).val("");
jQuery(field).removeClass('hint');
}
};
var showHint = function(field, text){
if (jQuery(field).val() === "") {
jQuery(field).val(text);
jQuery(field).addClass('hint');
}
};
var text;
for (fieldName in hints) {
text = hints[fieldName];
jQuery("input[name='"+fieldName+"']").val(text).focus((function(text) {
return function() {hideHint(this, text);};
})(text)).blur((function(text) {
return function() {showHint(this, text);};
})(text)).addClass('hint');
}
var submitButton = jQuery('#'+window.module.lp.form.data.formButtonId);
var submitAction = submitButton.data('events').click[0];
var field;
submitButton.unbind('click', submitAction);
submitButton.click(function(e) {
for (fieldName in hints) {
field = jQuery("input[name='"+fieldName+"']");
if (field.val() === hints[fieldName]) {
field.val('');
}
}
submitAction.handler(e);
for (fieldName in hints) {
field = jQuery("input[name='"+fieldName+"']");
if (field.val() === '') {
field.val(hints[fieldName]);
}
}
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment