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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:59:00+00:00 2026-06-14T19:59:00+00:00

I have a table that gets populated from a database. I have 2 conditions

  • 0

I have a table that gets populated from a database. I have 2 conditions that i need to apply

  1. Apply Zebra striping to the Table (Completed)
  2. Change Row color to red based td value

​`

<tr class="alt">
    <td class="status"><input type="text" value="One"></td>
    <td class>Received</td>
</tr>
<tr class="alt">
    <td class="status"><input type="text" value="One"></td>
    <td class>Received</td>
</tr>
<tr class="alt">
    <td class="status"><input type="text" value="Zero"></td>
    <td class>Received</td>
</tr>
<tr class="alt">
    <td class="status"><input type="text" value="One"></td>
    <td class>Received</td>
</tr>
<tr class="alt">
    <td class="status"><input type="text" value="Zero"></td>
    <td class>Received</td>
</tr>

​`

$(document).ready(function()
{
$("tr.alt:even").css("background-color", "#f0f8ff");
$("tr.alt:odd").css("background-color", "#fcfceb");
});

$(document).ready(function() {
   $('.status.val():contains("Zero")').closest('tr.alt').css('background-color', '#cd0000');
});

I wanna change the row color based on the input value

<td class="status"><input type="text" value="One"></td>

Here is a fiddle of what I’ve done so far

Would appreciate the help.

  • 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-14T19:59:01+00:00Added an answer on June 14, 2026 at 7:59 pm

    To change the tr (you’re using v 1.6.4 instead of latest so we need bind instead of on)

    $(document).ready(function(){
    
        $("tr.alt:even").addClass("even");
        $("tr.alt:odd").addClass("odd");
        $('td.status input').bind('change keyup', function(){
            var tr=$(this).closest('tr');
    
            if ($(this).val()=='Zero') tr.addClass('zero');       
            else tr.removeClass('zero');
    
        }).trigger('change'); // the trigger is to run this action on load
    });
    ​
    tr.odd
    {
        background-color:#fcfceb;
    }
    
    tr.even
    {
        background-color:#f0f8ff;
    }
    
    tr.odd.zero
    {
        background-color:#ff0000;
    }
    tr.even.zero
    {
        background-color:#cc0000;
    }
    

    Your HTML is a bit messed up though. You have missing quotes and <td class> is invalid.

    http://jsfiddle.net/MMEhc/158/

    EDIT: Updated version to suit the values being changed manually, not just those that are outputted (as I understood the question to be)

    http://jsfiddle.net/MMEhc/159/

    You’ll see I moved the background colours out of the HTML and into the CSS to make it easier to manipulate. I also adjusted the red for even or odd rows.

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

Sidebar

Related Questions

I have an Excel file that gets external data from database table. I need
I have a form that gets populated with data from the database. Before is
I have a sql table that gets populated via SQLBulkCopy from Excel. The copy
For example I have a dropdown box that gets a town from the table
We have a table with a Primary Key that gets populated on insert by
I have a ListBox that gets populated with items read from a JSON response.
I have a JTable that get's populated with data from a MySQL Table, but
I have a DropDownList that gets populated from SQL on page load. A user
I have a master page that gets all its images from a table on
I have multiple buttons that gets created in a table which all look like

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.