Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamic OnClick Button Event
    primarykey
    data
    text
    <p>I have a table that is created dynamically, and I want to put an EDIT / DELETE buttons with onclick events in each row.</p> <p>However, I don't know how to make them unique with the row's id and then make an onclick event for each so I can update/delete the values from the row.</p> <p>I tried:</p> <pre><code>&lt;INPUT TYPE='BUTTON' NAME='EDIT_PRODUCT_FROM_SEARCH' ID=".$row['alpha_p_ID']." VALUE='Delete'&gt; </code></pre> <p>But I don't know how to tell the event:</p> <pre><code>$('what to write here?').click(function() { }); </code></pre> <p>EDIT:</p> <p>The creation of button works but the onclick event don't. Code below:</p> <p>PHP button code</p> <pre><code>results_table = "&lt;table cellspacing='0' style='border: 1px solid #405D99'&gt;&lt;tr bgcolor='#405D99' style='color: white'&gt;&lt;th&gt;Main Image&lt;/th&gt;&lt;th&gt;Gallery Image 1&lt;/th&gt;&lt;th&gt;Gallery Image 2&lt;/th&gt;&lt;th&gt;Name&lt;/th&gt;&lt;th&gt;Type&lt;/th&gt;&lt;th&gt;Manufacturer&lt;/th&gt;&lt;th&gt;Quantity&lt;/th&gt;&lt;th&gt;Price-Wholesale&lt;/th&gt;&lt;th&gt;Price-Retail&lt;/th&gt;&lt;th&gt;Options&lt;/th&gt;&lt;/tr&gt;"; while($row = mysql_fetch_array($results)){ $results_table .= "&lt;tr&gt;"; $results_table .= "&lt;td bgcolor='#dfe3ee'&gt;&lt;a href='products/".$row['alpha_p_imglink_main']."' rel='lightbox'&gt;&lt;img src='products/".$row['alpha_p_imglink_main']."' width='150px' height='150px'; border='0'/&gt;&lt;/a&gt;&lt;/td&gt;"; $results_table .= "&lt;td bgcolor='#dfe3ee'&gt;&lt;a href='products/".$row['alpha_p_imglink_gal1']."' rel='lightbox'&gt;&lt;img src='products/".$row['alpha_p_imglink_gal1']."' width='150px' height='150px'; border='0'/&gt;&lt;/a&gt;&lt;/td&gt;"; $results_table .= "&lt;td bgcolor='#dfe3ee'&gt;&lt;a href='products/".$row['alpha_p_imglink_gal2']."' rel='lightbox'&gt;&lt;img src='products/".$row['alpha_p_imglink_gal2']."' width='150px' height='150px'; border='0'/&gt;&lt;/a&gt;&lt;/td&gt;"; $results_table .= "&lt;td bgcolor='#dfe3ee' align='center'&gt;$row[alpha_p_name_en]&lt;/td&gt;"; $results_table .= "&lt;td bgcolor='#dfe3ee' align='center'&gt;$row[alpha_p_type]&lt;/td&gt;"; $results_table .= "&lt;td bgcolor='#dfe3ee' align='center'&gt;$row[alpha_p_firm_owner]&lt;/td&gt;"; $results_table .= "&lt;td bgcolor='#dfe3ee' align='center'&gt;$row[alpha_p_quantity]&lt;/td&gt;"; $results_table .= "&lt;td bgcolor='#dfe3ee' align='center'&gt;$row[alpha_p_price_wholesale]&lt;/td&gt;"; $results_table .= "&lt;td bgcolor='#dfe3ee' align='center'&gt;$row[alpha_p_price_retail]&lt;/td&gt;"; $results_table .= "&lt;td colspan='1' rowspan='1' bgcolor='#f7f7f7' align='center'&gt;"; $results_table .= "&lt;a href='#' NAME='EDIT_PRODUCT_FROM_SEARCH' ID=".$row['alpha_p_ID']." CLASS='EDIT_BUTTON_CLASS'&gt;Edit&lt;/a&gt;"; $results_table .= "&lt;a href='#' NAME='DEL_PRODUCT_FROM_SEARCH' ID=".$row['alpha_p_ID']." CLASS='DELETE_BUTTON_CLASS'&gt;Delete&lt;/a&gt;"; $results_table .= "&lt;/tr&gt;"; } echo "Query: " . $query . "&lt;br /&gt;"; $results_table .="&lt;/table&gt;"; echo $results_table; </code></pre> <p>Onclick:</p> <pre><code> $('.EDIT_BUTTON_CLASS').on("click", 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"); }); </code></pre> <p>The onclick event should fill in a textbox with the id and post an alert. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload