Skip to:
Content
Pages
Categories
Search
Top
Bottom

Activity post-form.php jquery code hinting

  • @aljuk

    Member

    I’d like to do away with the “What’s New?” label, and instead display it inside the textarea of the post form as hint text, so that when the textarea receives focus, the text disappears, and when the textarea loses focus or is empty, the text reappears.

    So far, this is what I’ve come up with, based on a script I often use for the search form on WP client sites. The markup:

    <textarea name="whats-new" id="whats-new" cols="50" rows="10">@ What’s new?</textarea>

    The jq script:

    var active_color = '#333';
    var inactive_color = '#888';
    $("textarea#whats-new").css("color", inactive_color);
    var default_values = new Array();
    $("textarea#whats-new").focus(function() {
    if (!default_values[this.id]) {
    default_values[this.id] = this.value;
    }
    if (this.value == default_values[this.id]) {
    this.value = '';
    this.style.color = active_color;
    }
    $(this).blur(function() {
    if (this.value == '') {
    this.style.color = inactive_color;
    this.value = default_values[this.id];
    }
    });
    });

    It seems to be working great, except when an update is posted (ajax) the form reappears empty (ie. no hint text). when the form next gets a click (ie. focus set and then blurred) the hint text reappears. I’d like the hint text to populate the textarea after an update is posted, but I’m not very knowledgeable about ajax, and unsure if it’s possible. Any suggestions?

Viewing 1 replies (of 1 total)
  • @abysshorror

    Member

    Where are you putting the jq code ?

Viewing 1 replies (of 1 total)
  • The topic ‘Activity post-form.php jquery code hinting’ is closed to new replies.
Skip to toolbar