xxx.js
tableCreationForQuoteItem();
function tableCreationForQuoteItem()
{
var html_str='';
html_str += '<table>';
html_str += '<tr>';
html_str += '<th>Item</th><th>Description</th><th>Unit Cost</th><th>Tax Rate</th><th>Unit Of Measurement</th>';
html_str += '</tr>';
html_str += '<tr>';
html_str += '<td>'+$('#Quote_quoteitem_name') +'</td>';
html_str += '<td>'+$('#Quote_description') +'</td>';
html_str += '<td>'+$('#Quote_unitcost') +'</td>';
html_str += '<td>'+$('#Quote_taxrate_value') +'</td>';
html_str += '<td>'+$('#Quote_uom_value') +'</td>';
html_str += '</tr>';
html_str += '</table>';
alert(html_str);
}
I am getting the alert. But I want to place this table in certain field like Quote_item. How this can be done? Someone help please.
Using JQuery -
$('#Quote_item').html(html_str);
and using javascript -
document.getElementById("Quote_item").innerHTML = html_str;
You'd probably want something more like this
function tableCreationForQuoteItem() {
var table = $('<table />'),
tr1 = $('<tr />'),
tr2 = $('<tr />'),
th1 = $('<th />', {text : 'Item'}),
th2 = $('<th />', {text : 'Description'}),
th3 = $('<th />', {text : 'Unit Cost'}),
th4 = $('<th />', {text : 'Tax Rate'}),
th5 = $('<th />', {text : 'Unit Of Measurement'}),
td1 = $('<td />', {text : $('#Quote_quoteitem_name').text()}),
td2 = $('<td />', {text : $('#Quote_description').text()}),
td3 = $('<td />', {text : $('#Quote_unitcost').text()}),
td4 = $('<td />', {text : $('#Quote_taxrate_value').text()}),
td5 = $('<td />', {text : $('#Quote_uom_value').text()});
table.append(
tr1.append(
th1, th2, th3, th4, th5
),
tr2.append(
td1, td2, td3, td4, td5
)
);
$('element').append(table);
}
I didn't really get the question and since I don't have the required reputation to comment, I will give you the answer based on my predictions;
If you want the provided table to appear inside the HTML body ( for example ) then simply replace alert box with
document.getElementbyID("quote_item").innerHTML = html_str;
If you want the entire HTML to appear in the ,
create a pre tag inside a tag inside the
` pre id="quote_item"
/pre`
and replace the alert box in your javascript with; document.getElementbyID("quote_item").innerHTML = html_str;
P.S: enclose pre inside < >, stackoverflow's overriding it into an HTML content, not sure how the quotes here work as I'm still new :S