How to Read HTML table data and set in to String variable?

priyankajailia
Kilo Expert

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.

find_real_file.png

<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>

===========================================

find_real_file.png

=============================

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);

9 REPLIES 9

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);


My Bad Luck/// Line --- var table = gel("dataTable2"); ------------ is returning   null when i alert table var.


Try,



$('dataTable2') instead of gel function..



On Thu, 23 Jun 2016, 13:08 priyankajailia, <


Rivka Br
Tera Contributor

Hi,

Any find any solution for it?

 

RudhraKAM
Tera Guru

any solution for this ?