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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:42:40+00:00 2026-06-04T11:42:40+00:00

I need a help with the following code. There are 2 styles: activatedRow and

  • 0

I need a help with the following code. There are 2 styles: activatedRow and disactivatedRow. When a user clicks on a button (located inside the TD of a table), then either activatedRow or disactivatedRow is applied to a row. Selection of a style is based on current style. For instance, if a row is activated, then the button will disactivate it, and vice versa.

So, I have a problem with AJAX success. How to write IF statement to check current style of a row?

P.S. Also it would be interesting to know how to change TD IMG (button) for disactivated and activated rows.

CSS

.activatedRow td { 
    background-color:#FFFFFF !important;
    color: #000000 !important;
}
.disactivatedRow td { 
    background-color:#DFE1ED !important;
    color: #9896A8 !important;
}

Function “disactivateRow()”

<script type="text/javascript">
function disactivateRow(flightNum,obj){ 
           $.ajax({
                   type: "POST",
                   url: "callpage.php?page=tables/disactivate.php",
                   data: "flightNum=" + flightNum,
                   success: function(){
                       if ($(obj).hasClass("activatedRow")) {
                    $(obj).removeClass("activatedRow").addClass("disactivatedRow");
                } else
                    $(obj).removeClass("disactivatedRow").addClass("activatedRow");
               }
            });
}
</script>

Button inside the table

            <table id="newspaper-b" border="0" cellspacing="2" cellpadding="2" width = "100%">
                <thead>
                    <tr>
                        <th scope="col">Flt Num</th>
                        <th scope="col"></th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($result1 as $row):
                        $flightNum=$row['flightNum'];
                    ?>
                    <tr id="<?php echo $flightNum; ?>" class="edit_tr">
                        <td><?php echo $flightNum;?></td>
                        <td id="<?php echo $flightNum; ?>">
                             <div onclick='disactivateRow("<?php echo $flightNum; ?>", this)'>
                                <img src='images/disactivate.png' alt='Disactivate' />
                            </div>              
                        </td>
                    </tr>
                    <?php endforeach;?>
                </tbody>
            </table>

jQuery DataTable activation

 $(document).ready(function(){
      $('#newspaper-b').dataTable({
      "sPaginationType":"full_numbers",
      "bJQueryUI":true,
      'fnRowCallback': function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {     
          if (aData[0] == "0") {
                    nRow.className = "disactivatedRow";
              } else
                    nRow.className = "activatedRow"; 
            return nRow;
        }

      });   

ANSWER:

It works now:

      $(".disact_but" ).click(function() {
            var ID=$(this).attr('id');
                $.ajax({
                       type: "POST",
                       url: "callpage.php?page=tables/disactivate.php",
                       data: "flightNum=" + ID,
                       success: function(){
                            $("#"+ID).toggleClass("disactivatedRow", 100);
                       }
                });
            return false;
      });
  • 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-04T11:42:42+00:00Added an answer on June 4, 2026 at 11:42 am

    If obj is the TD to apply the style as your code indicates you could use toggleClass

    Add or remove one or more classes from each element in the set of matched elements, depending on either the class’s presence or the value of the switch argument.

    $(obj).closest('tr').toggleClass('disactivatedRow');
    $(obj).closest('tr').toggleClass('activatedRow');
    

    EDIT

    According new information you added, obj is a row’s child. closest method should give you the appropiate tr and then we can apply toggleClass

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

Sidebar

Related Questions

i need some help improving the following code - there is a conversion between
I need syntax help with the following code logic: I have a code block
I need help with the PHP code for the following: Get the text between
Newbie in need of help. The following code will count all the sub-folders under
I need help doing the following: a preprocessor macro label(x) shall output #x, e.g.,
I need some help extracting the following bits of information using regular expressions. Here
I need help on the best way to design a database/tables for the following
I need help debugging some odd file behavior in Python. Take the following script
I need some help writing a regex. I have the following strings, xxx.yyy.wwwwwaaa_IN_123 xxx.rrrttttt_IN_12355
I need some help with something... say I have the following form... <form name=

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.