php - get table cell data from and place a copy in another table -
two-part question: have 2 tables: 1 table items , other table selected items copied when add button clicked. after, when items wanted selected, there 'finished' button post items selected db.
i started javascript didn't far @ because jquery seems better suited i'm not familiar it
function addto() { var div = document.getelementbyid('fixeddiv','inside'); div.innerhtml = div.innerhtml + 'item added'; } <div id='fixeddiv'> <table align="center" id="tradee"> <th rowspan="2"> other item</th> <?php while($rowi =$item->fetch_assoc()) {?> <tr> <td> <?php echo $rowi['item_name']; ?> </td> <td><?php echo $rowi['item_description'];?></td> </tr> <?php } ?> </table>
<br> <table align="center" id="tradetable"> <th>cat_id</th> <th>name</th> <th>description</th> <?php while($row =$item_results->fetch_assoc()) {?> <tr> <td><?php echo $cat_id = $row['cat_id']; ?> </td> <td name="item_name"><?php echo $item_id = $row['item_name'];?></td> <td><?php echo $item_descrip = $row['item_description'];?></td> <td><input name ="submit" type="button" class="added" onclick="addto()" value="add" > </td> </tr> <?php } ?> </table>
i dont know excatly try do, hope helps bit:
here fiddle modifications on html , jquery: http://jsfiddle.net/4fart/5/
function addto(obj) { var $row = $(obj).parents("tr"); var $table = $("#tradee"); var item_name = $row.find(".item-name").text(); var item_desc = $row.find(".item-desc").text(); var newtr = $("<tr><td>"+item_name+"</td><td>"+item_desc+"</td></tr>"); $table.append(newtr); }
you should check markup of html, td
has no name
attribute, , ah <th>
wrapped <tr>
... maybe showing, , allready know :)
Comments
Post a Comment