Alvinrightback
Alvinrightback

Reputation: 215

JQuery Adding of row in table not working

I'm trying to add a row in a table from a data from another table. it says uncaught reference error.

here's the function

function addItem(id, name){
    bootbox.confirm("Are you sure?", function(result) {
        if (result) {
            $('#ingredients_table').append("<tr><td>"+name+"</td></tr>");
        }
    });
}

here's the table where I'm calling the js function

<?php foreach($inventory as $row): ?>
    <tr style="cursor: pointer;" data-toggle="tooltip" data-placement="top" title="Add ingredient" onclick="javascript:addItem(<?php echo $row->inventory_id; ?>, <?php echo $row->name; ?>)">
    <td><?php echo $row->name; ?></td>
</tr>
<?php endforeach; ?>

The ID is showing in the table when I switch them, but the name is not.

Upvotes: 0

Views: 82

Answers (1)

Pradeep
Pradeep

Reputation: 9717

Hope this will help you :

use '' (quotes) for javascript function arguments

 <?php foreach($inventory as $row): ?>
    <tr style="cursor: pointer;" data-toggle="tooltip" data-placement="top"
        title="Add ingredient" 
        onclick="javascript:addItem('<?php echo $row->inventory_id; ?>', '<?php echo $row->name; ?>')">

   <td><?php echo $row->name; ?></td>

Upvotes: 2

Related Questions