javascript - Adding Content to a div -
i using code content page on button click:
function getfilter(str){ $.ajax({ type: "get", //path php page data url:"getreceipt.php?table="+str+"", success:function(html){ //here success action //get data on div $("#receipt").html(html); } }); }
i use code add innerhtml content same div above content previous code created:
function updatecarlist(transaction, results) { //initialise listitems variable var listitems = ""; //get car list holder ul var listholder = document.getelementbyid("receipt"); //clear cars list ul listholder.innerhtml = "receipt<br>"; var i; //iterate through results (i = 0; < results.rows.length; i++) { //get current row var row = results.rows.item(i); listholder.innerhtml += "chair "+row.chair+"-<input type='hidden' id='chair[]' name='chair[]' value='"+row.chair+"' /><input type='hidden' id='item' name='item[]' value='"+row.item1+"' /><input type='hidden' id='price' name='price[]' value='"+row.price+"' />" + row.item1 + " - $" + row.price + " (<a href='javascript:void(0);' onclick='deletecar(" + row.id + ");'>delete car</a>)<br>"; } }
i've tried multiple ways including appendto, append, text, html, nothing seems work. way stands replaces code fetched getreceipt.php
could 1 offer advice? thanks!
"append" should work, quit using innerhtml if using jquery. create separate div , append rows div append div list holder.
... // code above //iterate through results var chairs = $('<div></div>'); (i = 0; < results.rows.length; i++) { var row = results.rows.item(i); var rowhtml = "<p>chair "+row.chair+"-<input type='hidden' id='chair[]' name='chair[]' value='"+row.chair+"' /><input type='hidden' id='item' name='item[]' value='"+row.item1+"' /><input type='hidden' id='price' name='price[]' value='"+row.price+"' />" + row.item1 + " - $" + row.price + " (<a href='javascript:void(0);' onclick='deletecar(" + row.id + ");'>delete car</a>)</p>"; chairs.append(rowhtml); } listholder.append(chairs); ... // code - function closing.
Comments
Post a Comment