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

  • SEARCH
  • Home
  • 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 6255595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:23:37+00:00 2026-05-24T14:23:37+00:00

Goal: Have first input box background-color change to green (on target.html) after redirecting. It

  • 0

Goal:

Have first input box background-color change to green (on target.html) after redirecting. It works if you go to the link explicitly (type it into the URL bar) in Google Chrome.

I’m using this version of Google Chrome:
13.0.782.112

It’s difficult to use jFiddle on this one, so I’ll just give you the code using the Content Delivery Network (CDN) jQuery file to make it easier for you.

See this question for more details:

Why doesn't initial page focus change input field to Green on Google Chrome?

Source page:
(name this page as source.html)

<html>
<head>
</head>
<body>

<a href="./target.html">click this hyperlink in Google Chrome and see if the background-color changes to green on the first input field on target.html</a>

</body>
</html>

Target page:
(name this page as target.html and place in same folder as source.html file)

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>

    <script type="text/javascript">

        function Change(obj, evt) {
            if (evt.type == "focus") {
                 $(obj).css('border-color', '#000000');
                 $(obj).css('background-color', '#90EE90');
            }
            else if (evt.type == "blur") {
                 $(obj).css('border-color', '#FFFFFF');
                 $(obj).css('background-color', '#7AC5CD');
            }
        }

        $(document).ready(function() {
            $("#Txt1").focus();
        });

    </script>

    <style type="text/css">

    .InputField
    {
        color: black;
        font-size: 12px;
        font-weight: bold;
        background-color: #7AC5CD;
    }

    </style>

</head>

<body>

<input id="Txt1" runat="server" class="InputField" onfocus="Change(this, event)" onblur="Change(this, event)" /><br />
<input id="Txt2" runat="server" class="InputField" onfocus="Change(this, event)" onblur="Change(this, event)" /><br />
<input id="Txt3" runat="server" class="InputField" onfocus="Change(this, event)" onblur="Change(this, event)" /><br />

</body>
</html>
  • 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-24T14:23:38+00:00Added an answer on May 24, 2026 at 2:23 pm

    Your best bet here is to bind those onfocus and onblur events dynamically instead of hardcoding them in the HTML. Something like this:

    $(document).ready(function() {
      // bind the events
      $('#Txt1, #Txt2, #Txt3').focus(function() {
        $(this).css('border-color', '#000000');
        $(this).css('background-color', '#90EE90');
      }).blur(function() {
        $(this).css('border-color', '#FFFFFF');
        $(this).css('background-color', '#7AC5CD');
      });
      // trigger the first focus event
      $('#Txt1').focus();
    });
    

    This code should replace all of your current JavaScript, as well as the onfocus and on blur attributes on those input boxes.

    With your current solution, it seems that there’s a bug in either jQuery or Chrome (or both) pertaining to triggering events that are bound in the HTML rather than through JavaScript. What happens, for whatever reason, is that the DOMContentLoaded event gets passed as the ‘evt’ variable instead of the onfocus event.

    If you’re interested in exploring that bug further and perhaps even filing a bug report, you can see what happens in more detail by adding a window.console.log(evt); statement to the first line of your Change function. Then open up the WebKit Web Inspector and look at the console, you’ll see the Event object there and you’ll notice that its type is ‘DOMContentLoaded’ even though it should actually be ‘focus’.

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

Sidebar

Related Questions

goal: I have the string 1234432144 I want to only replace the first 2
Let me first describe my goal: I have created an object with 3 properties:
I have this function. And its goal is to take the last character first
I have a button like this: <input type=button name=btn id=btn value=Proceed/> After all processes
So I have some html like so: <div id=avatar_choices> <label for=id_choice_0> <input id=id_choice_0 type=radio
I have two text boxes overlapping one another. The first text box, 'TextBox1', is
My goal was to have a template function that would take as an input
Final goal: Have a few java objects sharing the same base class persisted into
The goal is to have the member variable _AddValue point to the CreateFirstValue function
My goal is to have an Android phone (Samsung Galaxy Nexus) communicate with a

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.