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 973167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:14:19+00:00 2026-05-16T03:14:19+00:00

I haven’t been able to find a good answer to this issue. I’m trying

  • 0

I haven’t been able to find a good answer to this issue. I’m trying to get a better handle on some nicer looking/acting form elements with JQuery. Here’s the code I’m using so far:


$(document).ready(function() {
        $('.input').addClass('inputOut clear'); // Grey out text initially, default bg

        $('.input').each(function() { // Fill in form fields with labels
            var text = getAttr($(this));
            $(this).attr("value", text);
            $(this).hasfocus = false;
        });

        $('.input').mouseover(function() {
            if ($(this).hasfocus == true) return;
            else {
                var text = getAttr($(this));
                $(this).removeClass();
                if($(this).attr("value") == text) $(this).addClass('inputOver clear');
                else $(this).addClass('inputOver filled');
            }
        });

        $('.input').mouseout(function() {
            if ($(this).hasfocus == true) return;
            else {
                var text = getAttr($(this));
                $(this).removeClass();
                if(($(this).attr("value") == "") || ($(this).attr("value") == text)) $(this).addClass('inputOut clear');
                else $(this).addClass('inputOut filled');
            }
        });

        $('.input').focus(function() {
            $(this).hasfocus = true;
            $(this).removeClass();
            $(this).addClass('inputActive');
            var text = getAttr($(this));
            if($(this).attr("value") == text) {
                $(this).attr("value", "");
            }
        });

        $('.input').blur(function() {
            $(this).hasfocus = false;
            var text = getAttr($(this));
            $(this).removeClass();
            if($(this).attr("value") == "") {
                $(this).attr("value", text);
                $(this).addClass('inputOut clear');
            }
            else if(($(this).attr("value") != "") && ($(this).attr("value") != text)) {
                $(this).addClass('inputOut filled');
            }
        });

        // TEST SPANS
        $("#spans span.off").fadeIn(0);

    });

    function getAttr(element) {
        var text = element.attr("id");
        text = text.replace(/-/g," ");
        return text;
    }

Everything is working exactly as I’d like except for one thing. The mouseover/mouseout functions run on elements that have focus. Being mostly HTML/PHP, my Javascript skills are definitely a work in progress, so be nice. What I thought would work is to add a isFocused property (you can see what I tried in there), but it hasn’t worked as I’ve tried it so far.

Any help would be very much appreciated.

  • 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-16T03:14:20+00:00Added an answer on May 16, 2026 at 3:14 am

    You might want to refactor a bit.

    Create named functions, or [better]create an object (global is ok if You don’t have a lot of js out there) and put Your functions in that object so that they have names.

    MyAwesomeGlobalSomething={};
    MyAwesomeGlobalSomething.mOverFunc=function(){
      //the stuff You do
           if ($(this).hasfocus == true) return;
                else {
                    var text = getAttr($(this));
                    $(this).removeClass();
                    if($(this).attr("value") == text) $(this).addClass('inputOver clear');
                    else $(this).addClass('inputOver filled');
                }
    }
    //and more functions here
    

    You can now bind

     $('.input').mouseover(MyAwesomeGlobalSomething.mOverFunc);
    

    now

    $('.input').focus(function(){
      $(this).unbind('mouseover');
    //and more functions here
    });
    

    fixes Your problem and

    $('.input').blur(function(){
      $(this).mouseover(MyAwesomeGlobalSomething.mOverFunc);
    //and more functions here
    });
    

    returns the function binding

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

Sidebar

Related Questions

No related questions found

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.