Hidding a <div> with csv content

R

Ruskin Hardie

There is an iframe in my document that is hidden, which is the target for a
submitted form. When the form is submitted, some javascript sets a hidden
div, to displaying, eg:

document.getElementById('hiddendiv').style.display = '';

This div, simply has the words "building csv file, please wait", and is
used, because their is no indication in IE, as to what is happening, when
the user clicks on 'Results in CSV format', to return a report as a CSV
file.

The form is submitted to the hidden iframe. The asp page that is used in the
action of the form (run.csv.report.asp), has a content type of
"text/comma-separated-values" and a response header of
""Content-Disposition","filename=report.csv".

If the report returns no records, in the asp page, I can return either;
<html>
<body onload="
window.top.document.getElementById('hiddendiv').style.display='none';
alert('No records have been found for your report');"></body></html>

Or if the number of records is greater than 65535 (maximum number of rows
Excel can handle);
<html>
<body onload="
window.top.document.getElementById('hiddendiv').style.display='none';
alert('Too many records for Excel.\nPlease refine your search
criteria'');"></body></html>

However, if records are found, because the response is a csv, (ie:
response.write "field1,field2,field3" & vbCrLf) I can not use the javascript
of;

window.top.document.getElementById('hiddendiv').style.display='none';

Otherwise, this line is included in the csv file and the div is not hidden
when the report is finished.

Is there anyway to hide the div on the client, after the server has created
the report?
 
J

Jerry Kizziar

I am not 100% sure that this will work in all browsers, but you can query the
elements 'readyState' in a loop or something similar, I have made a quick
example to show:
(quick and dirty, i know)

<html>
<head>
<script language="javascript">
var timer
function xcheckStatus() {
timer = setTimeout('loopstatus()',20)
}
function loopstatus() {
clearTimeout(timer)
window.status = document.getElementById("myiframe").readyState
timer = setTimeout('loopstatus()',20)
}
</script>
</head>

<body onload="xcheckStatus()">
<input type="text" name="bob" id="myurl"><input type="button" name="btn"
value="go" onclick="document.getElementById('myiframe').src =
document.getElementById('myurl').value">
<iframe id="myiframe" src="testeriframe.asp" ></iframe>
</body>

</html>

When the readyState comes back as completed, it is done. However I did not
test this using an csv file, just html pages.
 
J

Jerry Kizziar

You have sparked my curiosity!!!

In further testing (and optimized codeing) I have discovered that you will
get back 'interactive' as the last readyState due to the save / open / cancel
dialog.

<html>
<head>
<script language="javascript" for="myiframe" event="onreadystatechange()">
document.getElementById("mytextarea").value =
document.getElementById("myiframe").readyState + "\n" +
document.getElementById("mytextarea").value
</script>
</head>
<body>
<input type="text" name="bob" id="myurl" />
<input type="button" name="btn" value="go"
onclick="document.getElementById('myiframe').src =
document.getElementById('myurl').value" />
<br />
<iframe id="myiframe" src="testeriframe.asp" ></iframe>
<br />
<textarea id="mytextarea" rows=10></textarea>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top