vorrei unire 2 script, ma andiamo con ordine
file html
Codice PHP:
<html>
<head>
<meta http-equiv="Content-Language" content="it">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Simple Ajax Example: CSV file -> HTML table</title>
<script language="javascript" type="text/javascript" src="ops.js">
</script>
<link href="styles.css" rel="stylesheet" type="text/css" />
</head>
<body onload="loadCSVFile('s.csv?', 'ResTable');">
<center>
<div id="ResTable"></div>
</center>
</body>
</html>
l' ops.js è cosi
Codice PHP:
var xmlhttp;
var destDiv;
var DEFAULT_SEPARATOR = ";";
function loadCSVFile(filePath, targetDiv){
xmlHttp = null;
// code for Firefox, Opera, ...
if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
// code for IE...
else
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlHttp != null) {
destDiv = targetDiv;
xmlHttp.onreadystatechange = stateChange;
xmlHttp.open("GET", filePath, true);
xmlHttp.send(null);
}
else {
alert("Your browser doesn't support xmlHttp: cannot read CSV file!");
}
}
function stateChange(){
// if xmlHttp is loaded...
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
var content = xmlHttp.responseText;
var res = makeHTMLTable(content);
document.getElementById(destDiv).innerHTML = res;
}
else {
alert("Problem retrieving CSV file");
}
}
}
function makeHTMLTable(content){
var res = "";
var lines = content.split("\n"); // split the content to get an array of lines
var numFields = lines[0].split(DEFAULT_SEPARATOR).length; // get number of fields
// open HTML table
res += "<table width='90%' id='ResTable'>";
// for simplicity, the first line of the CSV file
// contains the header cells captions
res += "<tr>";
var ths = lines[0].split(DEFAULT_SEPARATOR); // split the line to get header cell values
for (field = 0; field < numFields; field++) {
res += "<th>" + ths[field] + "</th>";
}
res += "</tr>";
// for every other line...
for (line = 1; line < lines.length - 1; line++) {
var tds = lines[line].split(DEFAULT_SEPARATOR); // split the line to get cell values
res += "<tr>";
for (field = 0; field < numFields; field++) {
if (tds[field] == undefined || tds[field] == "") {
tds[field] = "-";
}
res += "<td>" + tds[field] + "</td>";
}
res += "</tr>";
}
// close HTML table
res += "</table>";
return res;
}
ora vorrei poter aggiungere un'altro script, che mi permetta di nascondere alcune colonne a mio piacimento e a riguardo avevo trovato questo
Codice PHP:
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<script>
$(document).ready(function() {
$('input[type="checkbox"]').click(function() {
var index = $(this).attr('name').substr(3);
index--;
$('table tr').each(function() {
$('td:eq(' + index + ')',this).toggle();
});
$('th.' + $(this).attr('name')).toggle();
});
});
</script>
<body>
<table>
<thead>
<tr>
<th class="col1">Header 1 <input type="checkbox" name="col1" checked="checked" />Hide/Show</th>
<th class="col2">Header 2 <input type="checkbox" name="col2" checked="checked" />Hide/Show</th>
<th class="col3">Header 3 <input type="checkbox" name="col3" checked="checked" />Hide/Show</th>
</tr>
</thead>
<tr><td>Column1</td><td>Column2</td><td>Column3</td></tr>
<tr><td>Column1</td><td>Column2</td><td>Column3</td></tr>
<tr><td>Column1</td><td>Column2</td><td>Column3</td></tr>
<tr><td>Column1</td><td>Column2</td><td>Column3</td></tr>
</table>
<form>
<input type="checkbox" name="col1" checked="checked" /> Hide/Show Column 1
<input type="checkbox" name="col2" checked="checked" /> Hide/Show Column 2
<input type="checkbox" name="col3" checked="checked" /> Hide/Show Column 3
</form>
</body>
</html>
come posso unire i 2 script?