简体   繁体   中英

how to read the values of a dynamic html table from a text file?

I have generated a dynamic html table which takes input values with the help of html and javascript functions, now I want to plot a graph with the values from the table, these values have to be inserted into the table from an external text file which has to be uploaded to the page with the help of javascript, php JSON arrays to use PHPlot.

how to include a text file which has to be uploaded to fill the rows and columns of a dynamically generated html table ? or

how to read the values of a dynamic html table from a text file ?

HTML:

     <table id="contentTable" border="1" >
    <!-- Fill table programmatically -->

   <!-- include the .txt file which is present in the htdocs folder -->
    </table>

Javascript:

      function buildTable(val)
     {
   var myTable =document.getElementById("contentTable");
    var j=val;
var rows = [];
var cells = [];

   while (myTable.hasChildNodes()) {
    myTable.removeChild(myTable.lastChild);
   }


for( var i = 0; i < 1; i++ )
{
    rows[i] = myTable.insertRow(i);
    if(i%3==2)rows[i].addClass("every3rdrow");
    cells[i] = [];

    for( var x = 0; x < j ; x++ )
    {
        cells[i][x] =document.createElement((x==0)?"th":"td");
        cells[i][x].innerHTML = (x==0)?"<input>":"<input>";
        rows[rows.length - 1].appendChild(cells[i][x]);
    }
    }

    }
    buildTable();

i want to plot the graph with phplot.

use jQuery get ( http://api.jquery.com/jQuery.get/ )

$.get("whatever.txt", null, function(data, status, xhr){
   // append data which is content of whatever.txt
   $("table").append(data); // or whatever you want to do with it
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM