Form Hints 1.0

Created Tuesday 16th of September 2008 by Andreas Lagerkvist
Copyright © 2008 Andreas Lagerkvist (andreaslagerkvist.com)

Please have a look at the "Other Resources" for bug reports or further help on jQuery. Do not post bug reports or feature requests as comments to unrelated articles. If bug reporting on bugtracker.a-framework.org fails, e-mail me.

What it Does

Using this plug-in you can add a descriptive hint to any form-control you may have on your site.
Add a hint by giving the form-control a title-attribute. The hint will disappear and reappear as the user clicks the control.

How to Use

jQuery(document.body).formHints(); would give every form-control with a title-attribute a hint.

Run the plug-in on a parent-element of the form-controls you want to affect. If you run it on document.body every form-control with a title-attribute will get a hint.

Example

Example Code

HTML

<div id="jquery-form-hints-example">
<
form method="post" action="">

    <
p>
        <
label>
            
Dummy<br />
            <
input type="text" name="dummy" title="E.G. Dummy" />
        </
label>
    </
p>

    <
p><input type="submit" value="Ok" /></p>

</
form>
</
div>

JS

// I'm not actually running it because my site already uses formHints
// jQuery('#jquery-form-hints-example').formHints();

Source Code

jQuery.fn.formHints = function (conf) {
    var 
config jQuery.extend({
        
formControls:    'input[title], textarea[title]',
        
className:        'default-value'
    
}, conf);

    return 
this.each(function () {
        
jQuery(config.formControlsthis).each(function () {
            var 
jQuery(this);

            
t.formHint t.attr('title');
            
t.attr('title''');

            if (
t.val() === '' || t.val() == t.formHint) {
                
t.addClass(config.className).val(t.formHint);
            }

            
t.focus(function () {
                if (
t.val() == t.formHint) {
                    
t.val('').removeClass(config.className);
                }
            });
            
            
t.blur(function () {
                if (
t.val() === '' || t.val() == t.formHint) {
                    
t.addClass(config.className).val(t.formHint);
                }
            });
        });

        
// Remove hints on form submission
        
jQuery('form'this).submit(function () {
            
jQuery('.' config.classNamethis).removeClass(config.className).val('');
        });
    });
};

Download

Plug-in

Requires

Random jQuery Plug-ins

  • Removable File Upload

    This plug-in adds a "remove"-link next to input[type=file]:s that allows the user to remove a selected file from the input.

    Details

  • Ajax Loader

    Use this plug-in when you want to inform your visitors that a certain part of your page is currently loading. The plug-in adds a faded 'loading-div' o...

    Details

  • Center

    This little pluggy centers an element on the screen using either fixed or absolute positioning. Can be used to display messages, pop up images etc.

    Details

More Plug-ins

Recent Comments

  1. Andreas on "SleekPHP User Handling"

    Thank you for showing interest :) Were the docs en...

  2. ciptard on "SleekPHP User Handling"

    Ok, thank you

  3. Andreas on "SleekPHP User Handling"

    I might write a "getting started" article for Slee...

Page cached. Loaded in: 0.0075 second(s).
Last DB change: 2012-02-04 08:04:40
Last file change: 2011-10-03 07:42:35
Cache created: 2012-02-04 13:06:15