<table class="table" style="margin-bottom:0px!important">
<b>
<? if(!empty($channelBase['rep_ids']))
{
$s_id=$channelBase['id'];
$i=0;
$temp='';
$reps_channl=explode(",",$channelBase['rep_ids']);
foreach($reps_channl as $k)
{
$added_reps = $rep_names[$k];
if($i==0){
$temp.='<tr style="border-top:none;">';
}
$temp.="<td id='".$s_id."_".$k."' class='repclicked' style='border-top:none;'>$added_reps <a href='#' class='btn btn-xs btn-icon btn-circle ' onclick='delete_repid($k,$s_id);'><i class='fa fa-close'></i></a>
</td>";
$i++;
if($i==5)
{
$temp.='</tr>';
$i=0;
}
}
echo $temp;
}
?>
</b>
</table>
Here I have a td
id with a number value. here I am getting confusion on how to get the td
id in javascript. can anyone please help me.
3
Answers
Try this,
Here is how you can get
Ids
oftd
inside tableYou are trying to mix PHP and javascript, which you can not do. Everything in PHP is separate from javascript and the two do not have access to identifiers from each other.
The reason is this:
PHP code is completely run BEFORE the page is loaded. Once the page is loaded completely in PHP, it is then sent to the browser where the javascript acts upon whatever the result of the PHP code was.
Try this:
on a page enter:
Now load the page and right click on the page and go to “inspect ” or “view source”
you will see that the source of the page has no php code and is only
This is because all PHP code is processed BEFORE the page is loaded, whereas javascript is processed AFTER the page is sent to the browser.
You have to do everything involving PHP Ids first and completely separate from javascript, and likewise javascript must be completely separate from PHP.
For your case you must make a separate request in order to modify an array in PHP and then either reload the page or use AJAX to load the updated data.
The type of action you are trying to accomplish is impossible the way you are trying to do it.