Skip to content

Instantly share code, notes, and snippets.

@patrys
Created August 3, 2010 14:43
Show Gist options
  • Select an option

  • Save patrys/506492 to your computer and use it in GitHub Desktop.

Select an option

Save patrys/506492 to your computer and use it in GitHub Desktop.

Revisions

  1. patrys revised this gist Aug 16, 2010. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions jquery.placeholder.js
    Original file line number Diff line number Diff line change
    @@ -20,9 +20,9 @@ $(function() {

    setPlaceholder();

    $(this).focus(removePlaceholder);
    $(this).blur(setPlaceholder);
    $(this).parents("form").submit(removePlaceholder);
    fld.focus(removePlaceholder);
    fld.blur(setPlaceholder);
    fld.parents("form").submit(removePlaceholder);
    });
    }
    });
  2. patrys revised this gist Aug 16, 2010. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions jquery.placeholder.js
    Original file line number Diff line number Diff line change
    @@ -20,9 +20,9 @@ $(function() {

    setPlaceholder();

    $(this).focus(removePlacholder);
    $(this).focus(removePlaceholder);
    $(this).blur(setPlaceholder);
    $(this).parents("form").submit(removePlacholder);
    $(this).parents("form").submit(removePlaceholder);
    });
    }
    });
  3. patrys revised this gist Aug 3, 2010. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions jquery.placeholder.js
    Original file line number Diff line number Diff line change
    @@ -5,14 +5,14 @@ $(function() {
    var fld = $(this);

    function setPlaceholder() {
    if (fld.value == text || fld.value == '') {
    if (fld.val() == text || fld.val() == '') {
    fld.addClass('jqPlaceholder');
    fld.val(text);
    }
    }

    function removePlaceholder() {
    if (fld.value == text || fld.value == '') {
    if (fld.val() == text || fld.val() == '') {
    fld.val('');
    fld.removeClass('jqPlaceholder');
    }
  4. patrys revised this gist Aug 3, 2010. 1 changed file with 20 additions and 28 deletions.
    48 changes: 20 additions & 28 deletions jquery.placeholder.js
    Original file line number Diff line number Diff line change
    @@ -1,36 +1,28 @@
    $(function(){
    if (!("placeholder" in document.createElement("input"))) {
    $(function() {
    if (!('placeholder' in document.createElement('input'))) {
    $('input[placeholder], textarea[placeholder]').each(function() {
    var text = this.getAttribute('placeholder');
    var fld = $(this);

    var fld_current = this;
    function setPlaceholder() {
    if (fld.value == text || fld.value == '') {
    fld.addClass('jqPlaceholder');
    fld.val(text);
    }
    }

    if (this.value == '' || this.value == text) {
    $(this).addClass('jqPlaceholder');
    this.value = text;
    function removePlaceholder() {
    if (fld.value == text || fld.value == '') {
    fld.val('');
    fld.removeClass('jqPlaceholder');
    }
    }

    $(this).focus(function() {
    if(this.value == text || this.value == '') {
    this.value = '';
    $(this).removeClass('jqPlaceholder');
    };
    });

    $(this).blur(function() {
    if(this.value == text || this.value == '') {
    $(this).addClass('jqPlaceholder');
    this.value = text;
    };
    });

    $(this).parents("form").each(function() {
    $(this).submit(function() {
    if(fld_current.value == text) {
    fld_current.value = '';
    }
    });
    });

    setPlaceholder();

    $(this).focus(removePlacholder);
    $(this).blur(setPlaceholder);
    $(this).parents("form").submit(removePlacholder);
    });
    }
    });
  5. patrys created this gist Aug 3, 2010.
    36 changes: 36 additions & 0 deletions jquery.placeholder.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    $(function(){
    if (!("placeholder" in document.createElement("input"))) {
    $('input[placeholder], textarea[placeholder]').each(function() {
    var text = this.getAttribute('placeholder');

    var fld_current = this;

    if (this.value == '' || this.value == text) {
    $(this).addClass('jqPlaceholder');
    this.value = text;
    }

    $(this).focus(function() {
    if(this.value == text || this.value == '') {
    this.value = '';
    $(this).removeClass('jqPlaceholder');
    };
    });

    $(this).blur(function() {
    if(this.value == text || this.value == '') {
    $(this).addClass('jqPlaceholder');
    this.value = text;
    };
    });

    $(this).parents("form").each(function() {
    $(this).submit(function() {
    if(fld_current.value == text) {
    fld_current.value = '';
    }
    });
    });
    });
    }
    });