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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:01:18+00:00 2026-06-16T23:01:18+00:00

I have a <table> that is populated from a mysql database using php .

  • 0

I have a <table> that is populated from a mysql database using php. The <tr style="background-color:;"> is stored in the database for each record. I have made a small Javascript so that when the user selects (onfocus) or deselects (onblur) the <input>, the <tr> will change colors. I have it set so the color will be red when selected, but I want it to return to it’s default color once deselected.

Here is a snippet of my code, located within a while() loop, where $i is incremented:

<tr id="row$i">
<td><input type="text" onfocus="attON('row$i')" onblur="attOFF('row$i')"></td>
</tr>    

Here are my functions:

function attON(id)
    {
    var row = document.getElementById(id);
    row.style.backgroundColor = "#FF0000";
    }

function attOFF(id)
    {
    var row = document.getElementById(id);
    row.style.backgroundColor = "";
    }

As I’m sure you will guess, the backgroundColor does not change back to it’s default value, it changes to the <table> color instead. I was thinking of maybe capturing the default color in function attON(id) and setting it to a global variable would be the answer, but I don’t know how to do that. Obviously any other ideas are welcome. Cheers!

  • 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-06-16T23:01:19+00:00Added an answer on June 16, 2026 at 11:01 pm

    Try to edit this:

        function attOFF(id)
        {
            var row = document.getElementById(id);
            row.style.backgroundColor = "";
        }
    

    To this:

        function attOFF(id,realcolor)
        {
            var row = document.getElementById(id);
            row.style.backgroundColor = realcolor;
        }
    

    Then change attOFF('row$i') to attOFF('row$i','put here the PHP code to show the real color of the tr tag')

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

Sidebar

Related Questions

I have an HTML table populated with data from a MySQL database using a
My table is being populated using ajax from a mysql database. I have a
I am using PHP loops to populate an HTML table from a MySQL database.
I have a table which is populated by values obtained from mysql database. I
i am reading data from a mysql database table. I have populated a dropdown
I have used this statements to populate jcombobox from MySql database table using Hibernate
I have a JTable that get's populated with data from a MySQL Table, but
I have a table that is populated from a SQL database. Most of the
I have a large table that get populated from a view. This is done
I have a table Survey_Data_Response that is populated with an 'insert into' statement from

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.