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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:59:35+00:00 2026-06-09T16:59:35+00:00

I’m using dataTables to retrieve, display and organise data from a PHP script (which

  • 0

I’m using dataTables to retrieve, display and organise data from a PHP script (which in turn pulls the information from a MySQL database).

My dataTables table

Using the following code, dataTables retrieves the information and puts it into a.. well, table.

$('#content div').html( '<table id="example"></table>' );
var oTable = $('#example').dataTable( {
    "bJQueryUI": true,
    "bProcessing": true,
    "bServerSide": true,
    "sPaginationType": "full_numbers",
    "sAjaxSource": "dataTables.php",
    "aoColumns": [
        /* UID */           { "bSearchable": false,
                                "bVisible":  false },
        /* Datetime */      { "asSorting": [ "desc" ] },
        /* Staff Name */    null,
        /* Room */          null,
        /* Reason */        null,
        /* Urgency */       null,
        /* Processed? */    null ],
    "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
        var sDirectionClass;

        if ( aData[6] === null ) {
            sDirectionClass = "new";
            if ( row % 2 !== 0 )
                sDirectionClass = "new_odd";
        } else {
            sDirectionClass = "std";
        }

        row++;

        $(nRow).addClass( sDirectionClass );
        return nRow;
    }
} );

Most of this, I hope, is quite straightforward – this function takes the sAjaxSource property and looks at my dataTables.php file, which simply reads the MySQL DB and returns some information in a JSON-encoded format.

This all works fine, but I’m trying to turn one of my table’s columns into a clickable link.

The brief PHP for this is;

if ( $aColumns[$i] == "Processed" )
{
    $link = '<img src="tick.png" id="' . $aRow[ $aColumns[0] ] . '" />';
    $row[] = ( empty( $aRow[ $aColumns[$i] ] ) ) ? $link : $aRow[ $aColumns[$i] ];
}

The pseudo for that is basically if Processed field is NULL display an image with the UID of that row; otherwise display the value of Processed field.

Check or date

What I’d like to do now is make that image JS-clickable to run an AJAX function. I thought that the following code (in situ immediately after the above JS):

oTable.find('img').click(function(){
    var process = $(this).attr("id");
    $.ajax({
        url: "check_alerts.php",
        data: { process: id }
    }).done(function() { 
        oTable.fnDraw(false);
    });
});

Unfortunately, it appears to do nothing. I’d imagine this is because the img I’m creating is created in the DOM and as such when the above function runs, it won’t find any img tags.

How can I amend the code so that those images will run my AJAX function?

Thanks in advance,

  • 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-09T16:59:37+00:00Added an answer on June 9, 2026 at 4:59 pm

    To make sure that your new DOM elements also listen to the click event you should use “on”.

    oTable.on("click", "img", function() {
      var process = $(this).attr("id");
      $.ajax({
        url: "check_alerts.php",
        data: { process: id }
      }).done(function() { 
        oTable.fnDraw(false);
      });
    });
    

    See the documentation

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have a text area in my form which accepts all possible characters from
I have a view passing on information from a database: def serve_article(request, id): served_article
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.