1

I have a HTML table created and I want to read the value in cell and use it in a javascript.. Can anyone please suggest how to do this...

<table id="table1">
    <tr id="1">
        <td> pue </td>
        <td> 2.86 </td>
    </tr>
</table>

<script>
    var PUIDValue = document.getElementById("pue").value;  
    var chartData1 = [
            {
                "category": "Evaluation",
                "excelent": 20,
                "good": 20,
                "average": 20,
                "poor": 20,
                "bad": 20,
                "limit": 78,
                "full": 100,
                "bullet": PUIDValue
            }
        ];
amesome
  • 57
  • 1
  • 9
  • Its not part of your question so I wouldnt put it in the answer section, but jQuery makes tasks like this much easier... $($("table1").find("tr")[0]).find(td)[1].innerText, or something like that – QBM5 Feb 03 '16 at 14:19

2 Answers2

1

I am not sure about the size and which data you expect to use, but you could convert your table to a javascript array and then get the values from there.

Here is an example: Convert html table to array in javascript

Community
  • 1
  • 1
1
mainTr = document.getElementById('1'),
firstTd = mainTr.getElementsByTagName('td')[0]
Luca Giardina
  • 478
  • 4
  • 14