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>EquivalenceTable()</script>
This is the code :
Expand|Select|Wrap|Line Numbers
- function EquivalenceTable() {
- // 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='CaseSensitive' 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 = "ModelPubName" <!-- This sorts the results numerically --!>
- swdata.reset()
- var tableRecordCount = swdata.recordset.recordCount; // Counts the numbr of filtered records
- // Draws a table of filtered data if there are records to display
- if (tableRecordCount > 0 )
- {
- document.write("</p>");
- document.write("<table border='0' width='50%' summary='Table of equivalent OPDs'cellspacing='1' bgcolor='#000000' id='swtable' datasrc='#swdata' cellpadding='3' datapagesize='25' id='datatable'>");
- document.write("<thead>");
- document.write("<th bgcolor='#CC3300' width='50%'><p align='center'><a><font color='black'><strong>Equivalent OPD(s)</strong></font></a></p></th>");
- document.write("<th bgcolor='#F5CB99' width='70%'><p align='center'><a><font color='black'><strong>Processing Area</strong></font></a></p></th>");
- document.write("</thead>");
- document.write("<tbody>");
- document.write("<tr bgcolor='#F5CB99' valign='top'>");
- document.write("<td valign='top' bgcolor='#FFFFFF' align='left'><a datafld='Hyperlink'><span datafld='Name'></span></a></td>");
- document.write("<td valign='top' bgcolor='#FFFFFF'><p align='left'><span datafld='ModelPubName'></span></td>");
- document.write("</tr>");
- document.write("</tbody>");
- document.write("</table>");
- }
- }