Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7173071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:44:51+00:00 2026-05-28T15:44:51+00:00

I’ve got a problem with jQuery’s In-Field Labels plugin. Right now, it is working

  • 0

I’ve got a problem with jQuery’s In-Field Labels plugin. Right now, it is working completely perfectly on my page. It is a super awesome plugin that does a really good job.

But I need to hack it a bit to extend the functionality:

I need it to work with AJAX form data. In other words, I am trying to populate my form via AJAX. The plugin doesn’t work properly when fields are dynamically filled in, the plugin doesn’t even notice the input value. So Instead of fading out the label like it should, the label stays, so I essentially have the label and the field value overlapping each other.

Do you have any idea how I could go about hacking this plugin to work with AJAX values?

/*
 * In-Field Label jQuery Plugin
 * http://fuelyourcoding.com/scripts/infield.html
 *
 * Copyright (c) 2009 Doug Neiner
 * Dual licensed under the MIT and GPL licenses.
 * Uses the same license as jQuery, see:
 * http://docs.jquery.com/License
 *
 * @version 0.1
 */
(function($){

    $.InFieldLabels = function(label,field, options){
        // To avoid scope issues, use 'base' instead of 'this'
        // to reference this class from internal events and functions.
        var base = this;

        // Access to jQuery and DOM versions of each element
        base.$label = $(label);
        base.label = label;

        base.$field = $(field);
        base.field = field;

        base.$label.data("InFieldLabels", base);
        base.showing = true;

        base.init = function(){
            // Merge supplied options with default options
            base.options = $.extend({},$.InFieldLabels.defaultOptions, options);

            // Check if the field is already filled in
            if(base.$field.val() != ""){
                base.$label.hide();
                base.showing = false;
            };

            base.$field.focus(function(){
                base.fadeOnFocus();
            }).blur(function(){
                base.checkForEmpty(true);
            }).bind('keydown.infieldlabel',function(e){
                // Use of a namespace (.infieldlabel) allows us to
                // unbind just this method later
                base.hideOnChange(e);
            }).change(function(e){
                base.checkForEmpty();
            }).bind('onPropertyChange', function(){
                base.checkForEmpty();
            });
        };

        // If the label is currently showing
        // then fade it down to the amount
        // specified in the settings
        base.fadeOnFocus = function(){
            if(base.showing){
                base.setOpacity(base.options.fadeOpacity);
            };
        };

        base.setOpacity = function(opacity){
            base.$label.stop().animate({ opacity: opacity }, base.options.fadeDuration);
            base.showing = (opacity > 0.0);
        };

        // Checks for empty as a fail safe
        // set blur to true when passing from
        // the blur event
        base.checkForEmpty = function(blur){
            if(base.$field.val() == ""){
                base.prepForShow();
                base.setOpacity( blur ? 1.0 : base.options.fadeOpacity );
            } else {
                base.setOpacity(0.0);
            };
        };

        base.prepForShow = function(e){
            if(!base.showing) {
                // Prepare for a animate in...
                base.$label.css({opacity: 0.0}).show();

                // Reattach the keydown event
                base.$field.bind('keydown.infieldlabel',function(e){
                    base.hideOnChange(e);
                });
            };
        };

        base.hideOnChange = function(e){
            if(
                (e.keyCode == 16) || // Skip Shift
                (e.keyCode == 9) // Skip Tab
              ) return; 

            if(base.showing){
                base.$label.hide();
                base.showing = false;
            };

            // Remove keydown event to save on CPU processing
            base.$field.unbind('keydown.infieldlabel');
        };

        // Run the initialization method
        base.init();
    };

    $.InFieldLabels.defaultOptions = {
        fadeOpacity: 0.5, // Once a field has focus, how transparent should the label be
        fadeDuration: 300 // How long should it take to animate from 1.0 opacity to the fadeOpacity
    };


    $.fn.inFieldLabels = function(options){
        return this.each(function(){
            // Find input or textarea based on for= attribute
            // The for attribute on the label must contain the ID
            // of the input or textarea element
            var for_attr = $(this).attr('for');
            if( !for_attr ) return; // Nothing to attach, since the for field wasn't used


            // Find the referenced input or textarea element
            var $field = $(
                "input#" + for_attr + "[type='text']," + 
                "input#" + for_attr + "[type='password']," + 
                "textarea#" + for_attr
                );

            if( $field.length == 0) return; // Again, nothing to attach

            // Only create object for input[text], input[password], or textarea
            (new $.InFieldLabels(this, $field[0], options));
        });
    };

})(jQuery);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T15:44:52+00:00Added an answer on May 28, 2026 at 3:44 pm
       base.init = function(){
            // Merge supplied options with default options
            base.options = $.extend({},$.InFieldLabels.defaultOptions, options);
    
            // Check if the field is already filled in
            if(base.$field.val() != ""){
                //base.$label.hide();
                base.setOpacity(0.0);
                base.showing = false;
            }
            else //Added by Anand
            {
                base.setOpacity( blur ? 1.0 : base.options.fadeOpacity );
                base.showing = true;
            };
    
            base.$field.focus(function(){
                base.fadeOnFocus();
            }).blur(function(){
                base.checkForEmpty(true);
            }).bind('keydown.infieldlabel',function(e){
                // Use of a namespace (.infieldlabel) allows us to
                // unbind just this method later
                base.hideOnChange(e);
            }).change(function(e){
                base.checkForEmpty();
            }).bind('onPropertyChange', function(){
                base.checkForEmpty();
            }).bind('keyup',function(e){ //Added by Anand
                base.checkForEmpty();
            });
        };
    

    change your init function like above. Here I have added the else part for check the empty values. Then whenever you fill or clear the values in text fields, just call the infield label creating function again, like “$(“label”).inFieldLabels();”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.