How to Read HTML table data and set in to String variable?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2016 10:20 PM
Hi, I have a HTML table created on Catalog item. And On click on Add line button , one line gets added in to HTML area. So on submit I need the data from this HTML area to another String variable to process it further. Please help me on this.
<p> </p>
<p> </p>
<table id="dataTable2" style="border-collapse: collapse; border: 1px solid black;" width="100%">
<tbody>
<tr>
<td style="text-align: center; font: 14pt Calibri, sans-serif; background: #1f4e78; color: white; border: 1px solid black;" colspan="9">
<p><strong>New eSourcing Vendor Setup</strong></p>
</td>
</tr>
<tr><th style="text-align: center; font: 12pt Calibri, sans-serif; background: #c0c0c0; border: 1px solid black;" width="7%">
<p><strong>Supplier Type</strong></p>
</th><th style="text-align: center; font: 12pt Calibri, sans-serif; background: #c0c0c0; border: 1px solid black;" width="10%">
</th></tr>
</tbody>
</table>
===========================================
=============================
I tried below code but getElementById is not working
var table_rows = g_form.getValue('app_html') + '';
var table = document.getElementById("dataTable2").value;
var table = document.getElementById("dataTable2");
var arrRows = table.getElementsByTagName("tr");
var arrAllCells = table.getElementsByTagName("td");
var arrHeaders = table.getElementsByTagName("th");
//cells by rows
for(var i=0;i<arrRows.length;i++){
var arrRCells = arrRows[i].getElementsByTagName("td");
alert("arrRCells " +arrRCells);
}
g_form.setValue("hold_html_data", table);
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2016 12:30 AM
Ok. Rows are separated by "@" and column values are separated by comma. Try below code. If you face any issues, put few alerts in between those statements and check.
var table_rows = g_form.getValue('app_html');
var table = gel("dataTable2");
var arrRows = table.rows;
//cells by rows
var sHTML = "";
for(var i=0;i<arrRows.length;i++)
{
for(var cellcounter = 0 ; cellcounter < arrRows[i].cells.length ; cellCounter++)
{
sHTML += arrRows[i].cells[cellCounter].innerText + ";"
}
sHTML += "@"
}
g_form.setValue("hold_html_data", sHTML);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2016 12:37 AM
My Bad Luck/// Line --- var table = gel("dataTable2"); ------------ is returning null when i alert table var.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2016 12:57 AM
Try,
$('dataTable2') instead of gel function..
On Thu, 23 Jun 2016, 13:08 priyankajailia, <
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2022 09:43 AM
Hi,
Any find any solution for it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2025 06:26 AM
any solution for this ?