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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:09:17+00:00 2026-06-10T07:09:17+00:00

I am creating a table with information with ajax, echoing it with php. As

  • 0

I am creating a table with information with ajax, echoing it with php. As last option I want to add edit/delete buttons that will fill empty textfields with information based on row ID of the product. Everything is ok, but the onclick events given to the dynamic buttons aren’t working at all.

AJAX request code

function search_product() {
                var ajaxRequest;

                    try {
                        //opera 8.0+, firefox, safari..
                        ajaxRequest = new XMLHttpRequest();
                        }
                        catch (e){
                        // internet explorer browsers
                        try {
                            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
                            }
                            catch (e) {
                                try {
                                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
                                    }
                                    catch (e) {
                                        //something went wrong
                                        alert("Your browser doesn't support ajax, which is needed for our website functionality. Please update your browser or install a new browser");
                                        return false;
                                                }
                                        }
                                }
                ajaxRequest.onreadystatechange = function() {
                if(ajaxRequest.readyState == 4) {
                var ajaxDisplay = document.getElementById('P_SEARCH_DIV_RESULTS');
                ajaxDisplay.innerHTML = ajaxRequest.responseText;
                                                }
                                                            }
                    var p_name = document.getElementById('P_SEARCHBAR').value;
                    var p_option = document.getElementById('P_SEARCH_SELECT').value;
                    var get_string = "?search="+p_name+"&option="+p_option;

                ajaxRequest.open("GET", "elcoma_search_product.php" + get_string, true);
                ajaxRequest.send(null);
                }

PHP button code

results_table = "<table cellspacing='0' style='border: 1px solid #405D99'><tr bgcolor='#405D99' style='color: white'><th>Main Image</th><th>Gallery Image 1</th><th>Gallery Image 2</th><th>Name</th><th>Type</th><th>Manufacturer</th><th>Quantity</th><th>Price-Wholesale</th><th>Price-Retail</th><th>Options</th></tr>";
while($row = mysql_fetch_array($results)){
$results_table .= "<tr>";
$results_table .= "<td bgcolor='#dfe3ee'><a href='products/".$row['alpha_p_imglink_main']."' rel='lightbox'><img src='products/".$row['alpha_p_imglink_main']."' width='150px' height='150px'; border='0'/></a></td>";
$results_table .= "<td bgcolor='#dfe3ee'><a href='products/".$row['alpha_p_imglink_gal1']."' rel='lightbox'><img src='products/".$row['alpha_p_imglink_gal1']."' width='150px' height='150px'; border='0'/></a></td>";
$results_table .= "<td bgcolor='#dfe3ee'><a href='products/".$row['alpha_p_imglink_gal2']."' rel='lightbox'><img src='products/".$row['alpha_p_imglink_gal2']."' width='150px' height='150px'; border='0'/></a></td>";
$results_table .= "<td bgcolor='#dfe3ee' align='center'>$row[alpha_p_name_en]</td>";
$results_table .= "<td bgcolor='#dfe3ee' align='center'>$row[alpha_p_type]</td>";
$results_table .= "<td bgcolor='#dfe3ee' align='center'>$row[alpha_p_firm_owner]</td>";
$results_table .= "<td bgcolor='#dfe3ee' align='center'>$row[alpha_p_quantity]</td>";
$results_table .= "<td bgcolor='#dfe3ee' align='center'>$row[alpha_p_price_wholesale]</td>";
$results_table .= "<td bgcolor='#dfe3ee' align='center'>$row[alpha_p_price_retail]</td>";
$results_table .= "<td colspan='1' rowspan='1' bgcolor='#f7f7f7' align='center'>";
$results_table .= "<a href='#' NAME='EDIT_PRODUCT_FROM_SEARCH' ID=".$row['alpha_p_ID']." CLASS='EDIT_BUTTON_CLASS'>Edit</a>";
$results_table .= "<a href='#' NAME='DEL_PRODUCT_FROM_SEARCH' ID=".$row['alpha_p_ID']." CLASS='DELETE_BUTTON_CLASS'>Delete</a>";
$results_table .= "</tr>";
}
echo "Query: " . $query . "<br />";
$results_table .="</table>";
echo $results_table;

Onclick:

                        $('.EDIT_BUTTON_CLASS').on("click", function(event) {
                    var e_id = this.id;
                    var p_edit_id = $('input[name=P_NAME_EDIT]');
                    (p_edit_id).val(e_id);
                    alert("aaa");
                    });

The test onclick should fill a textfield with the ID and post an alert. However, like explained nothing works.

  • 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-10T07:09:19+00:00Added an answer on June 10, 2026 at 7:09 am

    Bind an event handler on document’s click event.
    Then the click on '.EDIT_BUTTON_CLASS' will bubble and the document’s event handler will
    determine that it’s an element for which the handler’s logic should be executed:

    $(document).on("click", '.EDIT_BUTTON_CLASS', function(event) {
        var e_id = $(this).attr('id');
        var p_edit_id = $('input[name=P_NAME_EDIT]');
        (p_edit_id).val(e_id);
        alert("aaa");
    });
    

    DEMO

    UPDATE – Event bubbling

    enter image description here

    As we can see on this picture, the click has been performed on the <img> element. This element has no own click event handler, but document has. So the event bubbles up and our document’s click event handler performs the check is the event target has a class 'EDIT_BUTTON_CLASS'. And if yes then it’s going to perform the declared operations.

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

Sidebar

Related Questions

I am creating an application where I want to add metadata about table fields
I am creating a user information edit dialog that fetches edit-user information using $.post
Hi Following is the syntax for creating table in mysql. I want to create
After creating a table (by migration), I want to insert some entries directly. How
I'm creating a table inside a repeater programmatically. My problem is that the cells
I am creating a table where it has a foreign key so that it
I am creating a table for an application that handles scheduling and deals with
I'm creating a table in an asp.net code behind dynamically, and I want to
I have a page that, when accessed displays a table of information related to
I've been creating imports that use SSIS to import data into a temp table,

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.