Hello guys,
I need your help with a combined JavaScript-PHP code…
Let me post the codes
First, the PHP code:
[code=php]
<div id=”shop_product_table” style=”float: left; margin-left: 0px; width: 205px;”>
‘;
$search_pm = mysql_query(“SELECT * FROM “.$table_articles.” WHERE pm=’1′”) or trigger_error (mysql_errno());
$num_search_pm = mysql_num_rows($search_pm);
if ($num_search_pm > 0) {
$table_visibility = ‘visibility: visible;’;
} else {
$table_visibility = ‘visibility: hidden;’;
}
echo ‘
<table id=”Table_Pm” cellspacing=”0″ style=”‘.$table_visibility.'”>
‘;
if ($num_search_pm > 0) {
echo ‘<tr style=”height: 10px;” id=”menu_left_title”>
<td width=”80″ align=”left” style=”font-size: 12px; padding-left: 5px;”>Afisare</td>
<td width=”80″ style=”font-size: 12px;”>Cod produs</td>
<td width=”40″ align=”center” style=”font-size: 12px;”>Sterge</td>
</tr>’;
while ($row_search_pm = mysql_fetch_array($search_pm)) {
//print ‘in while<br />’;
echo ‘<tr>’;
print ‘<td width=”90″ align=”left” style=”padding-left: 5px;”>Detalii</td>’;
print ‘<td width=”100″>’.$row_search_pm[‘code_article’].'</td>’;
print ‘<td width=”20″ align=”center” style=”padding-right: 5px;”>’;
print ‘<img id=”deleteImage” src=”images/icon_trash.png” onclick=”deleteTheRow(this); undressModel(‘.$row_search_pm[‘code_article’].’);” />’;
echo ‘</td>’;
echo ‘</tr>’;
}
}
echo ‘
<!– START content from the javascript–>
<!– END content from the javascript–>
</table>
</div>
Now the Javascript code
[CODE]function deleteTheRow(src) {
var oRow = src.parentElement.parentElement;
document.all(“Table_Pm”).deleteRow(oRow.rowIndex);
}
function undressModel(u_idImg) {
var ver_elm_fata = document.getElementById(”+ u_idImg +’_fata’);
if (null !== ver_elm_fata) {
ver_elm_fata.parentNode.removeChild(ver_elm_fata);
}
var ver_elm_spate = document.getElementById(”+ u_idImg +’_spate’);
if (null !== ver_elm_spate) {
ver_elm_spate.parentNode.removeChild(ver_elm_spate);
}
$.get(‘phpinclude/undressModel.php’, {‘code_articole’: ”+ u_idImg +”}, function(d) {
alert(”+ d +”);
});
undress_model_fata.removeAttribute (‘id’, ”+ u_idImg +’_fata’);
undress_model_spate.removeAttribute (‘id’, ”+ u_idImg +’_spate’);
}
The problem is that if I call this javascript function from another javascript by adding the following:
[QUOTE]
cell3_elm.setAttribute(‘onclick’,’stergeRow(this); undressModel(‘+ d_idImg +’);’); // for IE/Firefox
cell3_elm.onclick = function() {stergeRow(this); undressModel(d_idImg);}; // for Chrome/Opera/Safari
cell3.appendChild(cell3_elm);
the function works like clockwork…
But when I add the function to a static table with values pulled from a mysql_database, the function won’t “see” the variable (in this case u_idImg)
Basically it will “lose it”.
Any idea’s on how this can be fixed ?
I’ll appreciate any help and thank everyone in advance!
My best regards,
Michael