Skip to content

Instantly share code, notes, and snippets.

@GaryUnbounce
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save GaryUnbounce/9062746 to your computer and use it in GitHub Desktop.

Select an option

Save GaryUnbounce/9062746 to your computer and use it in GitHub Desktop.
<script type="text/javascript">
jQuery(document).ready(function() {
var hints = {
"name": "John Doe",
"email": "you@youremail.com",
"phone_number": "555-555-5555",
"company": "Company 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("#"+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 field;
submitButton.mousedown(function(e) {
for (fieldName in hints) {
field = jQuery("#"+fieldName);
if (field.val() === hints[fieldName]) {
field.val('');
}
}
});
submitButton.click(function(e) {
for (fieldName in hints) {
field = jQuery("#"+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