Raghib Ahsan Raghib Ahsan - 5 months ago 16x
PHP Question

Selecting a unique cell from a dynamic generated table

Here goes my problem: this is the table

enter image description here

I want to click on delete column of a particular row say row no2 then I should select the value

of that particular row row no.2

The problem is that table is being generated dynamically by the following code

<?php for($i=0;$i<count($detail1);$i++):?>
<td><button onclick='alert("<?=$detail1[$i]['password']?>")' > change</button></td>
<td><i class=" del glyphicon glyphicon-minus"></i></td>
<?php endfor; ?>

I am trying to select that particular cell of a row by applying this jQuery function but I am getting error in the console and it's not working too

the variable
is going to save that particular cell value

var answer = confirm ("Are you sure you want to delete from the database?");
var id= <?php echo $detail1[$i]['id'];?>;

if (answer)
// your ajax code
type: 'POST',
url: '<?php echo base_url(); ?>Admin/del', //We are going to make the request to the method "list_dropdown" in the match controller
data: {'id':id}, //POST parameter to be sent with the tournament id
//With the ".html()" method we include the html code returned by AJAX into the matches list
success: function(resp) {
alert('you have successfully deleted');
error: function(resp) {

The error in the console is

SyntaxError: expected expression, got '<'

What I figured out that this line var
id= <?php echo $detail1[$i]['id'];?>
is causing error and making my jQuery call not functioning

Is there alternative to select that particular cell OFFICED OF A ROW from a dynamic table by any event?

var id= <?php echo $detail1[$i]['id'];?>

Looks like $i is not defined, so id should be null. And so the issue.

Select id something like this. Please test, might need extra work:

var id= $(this).closest('tr').find('td.id').html();

And HTML <td> of id line should look something like:

<td class="id"><?=$detail1[$i]['id'];?></td>