I wrote one a week ago. As well as adding adn removing the titles it
adds and removes extra CSS classes so you can change the way it is
displayed.

Usage:
$('#contactform').inputAutoTitles();

in your forms use <input type="text" title="Email Address"
name="email" />

jQuery.fn.extend({
        inputAutoTitles: function(options) {
                // stick all the titles
                this.find('input').each(function(i) {
                        var title=$(this).attr('title');
                        if ($(this).val()=='') {
                                $(this).val(title).addClass('waiting')
                                        .blur(function(){
                                                $(this).removeClass('active');
                                                if ($(this).val()=='' || 
$(this).val()==title) $
(this).addClass('waiting').val(title);
                                        })
                                        .focus(function(){
                                                
$(this).removeClass('waiting').addClass('active');
                                                if ($(this).val()==title) 
$(this).val('');
                                        });
                                //
                        }
                        else
                        {
                                $(this).unbind('click');
                        }
                });
                // clear the titles on submit
                $(this).submit(function(){
                        $(this).find('input').each(function(i){
                                if ($(this).attr('title')==$(this).val()) 
$(this).val('');
                        });
                });
        }
});




On Jul 18, 9:18 am, Michael Schwarz <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I did this here:
>
> /* get default value of any <input value="this here"> and make it disappear 
> when the user focusses the input field
> when the focus is taken from that field (blur), do this:
> if nothing was entered by the user, set back the default value,
> otherwise don't mess with the users input  */
>
> $('input').focus(function(){
>         var defaultText = $(this).val();
>         $(this).val('');
>
>         $("input").blur( function () {
>         var userInput = $(this).val();
>
>                 if (userInput == ''){
>                         $(this).val(defaultText);
>                 }
>         });
>
> });
>
> on this HTML:
>
> <div id="search">
> <form action="/portal/wps/portal/PortalSearch">
> <label for="searchFor">Search: </label>
> <input name="searchFor" class="inputField" id="searchFor" type="text" 
> value="Search">
> <input type="image" src="theme/images/btn_search.gif" alt="go">
> </form>
> </div><!-- #search END -->
>
> Is that what you want to do? I guess it could be optimized, though....
>
> Regards
> Michael
>
> Original message Donnerstag, 17. Juli 2008, 18:19:
>
> > Is there a plugin for this by chance? I know it's pretty quick to write, but
> > wanted to find out if someone's already done it better than I could.
>
> > Also, would toggle() work for this sort of thing? Is there a focus/blur
> > toggle in the jQuery core?

Reply via email to