Skip to content

Instantly share code, notes, and snippets.

@stephensprinkle-zz
Created December 19, 2012 02:15

Revisions

  1. @stephensprinkle stephensprinkle revised this gist Dec 19, 2012. 1 changed file with 25 additions and 25 deletions.
    50 changes: 25 additions & 25 deletions jquery-default-input-values
    Original file line number Diff line number Diff line change
    @@ -2,36 +2,36 @@ Note: for each input you have to set both a `placeholder` and a `value`.

    Example:
    <input name="home_phone"
    type="text"
    value="Phone Number"
    placeholder="Phone Number" />
    type="text"
    value="Phone Number"
    placeholder="Phone Number" />

    Function:

    function defaultInputValues(){
    //Handle Cross Browser Default Input Values
    var placeholderSupported = !!( 'placeholder' in document.createElement('input') );
    //Handle Cross Browser Default Input Values
    var placeholderSupported = !!( 'placeholder' in document.createElement('input') );

    if (placeholderSupported === true){
    $('input:not([type="submit"])').val('');
    } else{
    $("input")
    .focus(function() {
    if (this.value === this.defaultValue) {
    this.value = '';
    }
    })
    .blur(function() {
    if (this.value === '') {
    this.value = this.defaultValue;
    }
    });
    };

    $("select").bind("focus", function () {
    $(this).children('option[value="defaultValue"]').remove();
    $(this).removeClass('default-value');
    if (placeholderSupported === true){
    $('input:not([type="submit"])').val('');
    } else{
    $("input")
    .focus(function() {
    if (this.value === this.defaultValue) {
    this.value = '';
    }
    })
    .blur(function() {
    if (this.value === '') {
    this.value = this.defaultValue;
    }
    });
    };

    $("select").addClass('default-value');
    $("select").bind("focus", function () {
    $(this).children('option[value="defaultValue"]').remove();
    $(this).removeClass('default-value');
    });

    $("select").addClass('default-value');
    }
  2. @stephensprinkle stephensprinkle revised this gist Dec 19, 2012. 1 changed file with 10 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions jquery-default-input-values
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,13 @@
    Note: for each input you have to set both a `placeholder` and a `value`.

    Example:
    <input name="home_phone"
    type="text"
    value="Phone Number"
    placeholder="Phone Number" />

    Function:

    function defaultInputValues(){
    //Handle Cross Browser Default Input Values
    var placeholderSupported = !!( 'placeholder' in document.createElement('input') );
  3. @stephensprinkle stephensprinkle created this gist Dec 19, 2012.
    27 changes: 27 additions & 0 deletions jquery-default-input-values
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    function defaultInputValues(){
    //Handle Cross Browser Default Input Values
    var placeholderSupported = !!( 'placeholder' in document.createElement('input') );

    if (placeholderSupported === true){
    $('input:not([type="submit"])').val('');
    } else{
    $("input")
    .focus(function() {
    if (this.value === this.defaultValue) {
    this.value = '';
    }
    })
    .blur(function() {
    if (this.value === '') {
    this.value = this.defaultValue;
    }
    });
    };

    $("select").bind("focus", function () {
    $(this).children('option[value="defaultValue"]').remove();
    $(this).removeClass('default-value');
    });

    $("select").addClass('default-value');
    }