I'm pretty new to javascript so this may well be a really basic error, but I've spent hours trying to fix it with no joy.
I have written some code which looks in a CSV file, filters it depending on the web page you are looking at and then displays the results as a table. There is an 'IF' statement which only writes the table if there are filtered records to display.
Now for the bit that is driving me crazy . . . The function only works if there is an 'alert' statement in the code. If this is removed the table doesn't display, when it's there it does ! It's as though the page loads before executing the filter count or IF and the alert gives it that time to do so. If I take out the alert and the IF then it works fine, but I get tables when there is no data and that's what I want to avoid.
Strangely if you load the page (it doesn't work), navigate to another page and then press the back button to the original page, it does work without the alert being present ?????
The code is sitting in a JS file and is called from within the body of a web page by : <script>Equival enceTable()</script>
This is the code :
[CODE=javascript]function EquivalenceTabl e() {
// Determines the path of the page
var sPath = window.location .pathname;
// Sets up a databound table
document.write( "<object id='swdata' CLASSID='clsid: 333C7BC4-460F-11D0-BC04-0080C7055A83' >");
document.write( "<param name='DataURL' value='/showcase1/OPD_Alpha_List/ee_nnw1.csv'>") ;
document.write( "<param name='UseHeader ' value='True'>") ;
document.write( "<param name='CaseSensi tive' value='False'>" );
document.write( "</object>");
alert('Hello'); // REMOVE THIS AND CODE STOPS WORKING !
// Filter the table on the path value
swdata.filter = ""
swdata.filter = "Source = *" + sPath +"*";
swdata.sort = "ModelPubNa me" <!-- This sorts the results numerically --!>
swdata.reset()
var tableRecordCoun t = swdata.recordse t.recordCount; // Counts the numbr of filtered records
// Draws a table of filtered data if there are records to display
if (tableRecordCou nt > 0 )
{
document.write( "</p>");
document.write( "<table border='0' width='50%' summary='Table of equivalent OPDs'cellspacin g='1' bgcolor='#00000 0' id='swtable' datasrc='#swdat a' cellpadding='3' datapagesize='2 5' id='datatable'> ");
document.write( "<thead>");
document.write( "<th bgcolor='#CC330 0' width='50%'><p align='center'> <a><font color='black'>< strong>Equivale nt OPD(s)</strong></font></a></p></th>");
document.write( "<th bgcolor='#F5CB9 9' width='70%'><p align='center'> <a><font color='black'>< strong>Processi ng Area</strong></font></a></p></th>");
document.write( "</thead>");
document.write( "<tbody>");
document.write( "<tr bgcolor='#F5CB9 9' valign='top'>") ;
document.write( "<td valign='top' bgcolor='#FFFFF F' align='left'><a datafld='Hyperl ink'><span datafld='Name'> </span></a></td>");
document.write( "<td valign='top' bgcolor='#FFFFF F'><p align='left'><s pan datafld='ModelP ubName'></span></td>");
document.write( "</tr>");
document.write( "</tbody>");
document.write( "</table>");
}
}[/CODE]
I have written some code which looks in a CSV file, filters it depending on the web page you are looking at and then displays the results as a table. There is an 'IF' statement which only writes the table if there are filtered records to display.
Now for the bit that is driving me crazy . . . The function only works if there is an 'alert' statement in the code. If this is removed the table doesn't display, when it's there it does ! It's as though the page loads before executing the filter count or IF and the alert gives it that time to do so. If I take out the alert and the IF then it works fine, but I get tables when there is no data and that's what I want to avoid.
Strangely if you load the page (it doesn't work), navigate to another page and then press the back button to the original page, it does work without the alert being present ?????
The code is sitting in a JS file and is called from within the body of a web page by : <script>Equival enceTable()</script>
This is the code :
[CODE=javascript]function EquivalenceTabl e() {
// Determines the path of the page
var sPath = window.location .pathname;
// Sets up a databound table
document.write( "<object id='swdata' CLASSID='clsid: 333C7BC4-460F-11D0-BC04-0080C7055A83' >");
document.write( "<param name='DataURL' value='/showcase1/OPD_Alpha_List/ee_nnw1.csv'>") ;
document.write( "<param name='UseHeader ' value='True'>") ;
document.write( "<param name='CaseSensi tive' value='False'>" );
document.write( "</object>");
alert('Hello'); // REMOVE THIS AND CODE STOPS WORKING !
// Filter the table on the path value
swdata.filter = ""
swdata.filter = "Source = *" + sPath +"*";
swdata.sort = "ModelPubNa me" <!-- This sorts the results numerically --!>
swdata.reset()
var tableRecordCoun t = swdata.recordse t.recordCount; // Counts the numbr of filtered records
// Draws a table of filtered data if there are records to display
if (tableRecordCou nt > 0 )
{
document.write( "</p>");
document.write( "<table border='0' width='50%' summary='Table of equivalent OPDs'cellspacin g='1' bgcolor='#00000 0' id='swtable' datasrc='#swdat a' cellpadding='3' datapagesize='2 5' id='datatable'> ");
document.write( "<thead>");
document.write( "<th bgcolor='#CC330 0' width='50%'><p align='center'> <a><font color='black'>< strong>Equivale nt OPD(s)</strong></font></a></p></th>");
document.write( "<th bgcolor='#F5CB9 9' width='70%'><p align='center'> <a><font color='black'>< strong>Processi ng Area</strong></font></a></p></th>");
document.write( "</thead>");
document.write( "<tbody>");
document.write( "<tr bgcolor='#F5CB9 9' valign='top'>") ;
document.write( "<td valign='top' bgcolor='#FFFFF F' align='left'><a datafld='Hyperl ink'><span datafld='Name'> </span></a></td>");
document.write( "<td valign='top' bgcolor='#FFFFF F'><p align='left'><s pan datafld='ModelP ubName'></span></td>");
document.write( "</tr>");
document.write( "</tbody>");
document.write( "</table>");
}
}[/CODE]
Comment