Please help with reading from a textfile on webserver

R

Rose Chambers

How can I insert preformatted text from a file on the web server
into a table's cell? And then swapped the text in response to an
onClick event.

Something like this.........

<table>
<tr><td>
<img name="swap_grph" src="http://www.mydomain.com/graphs/piechart1.jpg">
</tr></td><tr><td>
< SOMETAG name="swap_text" src="http://www.mydomain.com/textfiles/datatable1.txt">
</tr></td><tr><td>
<form>
<input type="button" value="Next" onclick="swap_dataset()"/>
</form>
</tr></td>
</table>

<script>
function swap_dataset() {
document.images.swap_grph.src="http://www.mydomain.com/graphs/bargraph2.jpg";
document.SOMETHING.swap_text.src="http://www.mydomain.com/textfiles/datatable2.txt";
}
</script>


Thanks.
 
M

McKirahan

Rose Chambers said:
How can I insert preformatted text from a file on the web server
into a table's cell? And then swapped the text in response to an
onClick event.

Something like this.........

<table>
<tr><td>
<img name="swap_grph" src="http://www.mydomain.com/graphs/piechart1.jpg">
</tr></td><tr><td>
< SOMETAG name="swap_text" src="http://www.mydomain.com/textfiles/datatable1.txt">
</tr></td><tr><td>
<form>
<input type="button" value="Next" onclick="swap_dataset()"/>
</form>
</tr></td>
</table>

<script>
function swap_dataset() {
document.images.swap_grph.src="http://www.mydomain.com/graphs/bargraph2.jpg"
;
document.SOMETHING.swap_text.src="http://www.mydomain.com/textfiles/datatabl
e2.txt";
}
</script>


Thanks.

Will this help? Watch for word-wrap.

<html>
<head>
<title>swapper.htm</title>
<script type="text/javascript">
var url1 = "http://www.mydomain.com/graphs/"
var url2 = "http://www.mydomain.com/textfiles/"
function init_dataset() {
document.images.swap_grph.src = url1 + "piechart1.jpg";
document.getElementById("swap_text").innerHTML = fetch(url2 +
"datatable1.txt");
}
function swap_dataset() {
document.images.swap_grph.src = url1 + "bargraph2.jpg";
document.getElementById("swap_text").innerHTML = fetch(url2 +
"datatable2.txt");
}
function fetch(sURL) {
var sTXT = "";
var oXML = new ActiveXObject("Microsoft.XMLHTTP");
oXML.Open("GET",sURL,false);
oXML.send();
try {
sTXT = oXML.ResponseText;
} catch(e) {
sTXT = "[" + e.Description + "]";
}
return sTXT;
}
</script>
</head>
<body onload="init_dataset()">
<table>
<tr>
<td><img name="swap_grph" src=""></td>
</tr>
<tr>
<td><span id="swap_text"></span></td>
</tr>
<tr>
<td><input type="button" value="Next" onclick="swap_dataset()" /></td>
</tr>
</table>
</body>
</html>

P.S. Your tags were switched: "</tr></td>".
 
R

Randy Webb

McKirahan said:

Will this help? Watch for word-wrap.

<--snip-->

Did you test it in anything other than IE?
The group FAQ covers this very thing.

function fetch(sURL) {
var sTXT = "";
var oXML = new ActiveXObject("Microsoft.XMLHTTP");
oXML.Open("GET",sURL,false);
oXML.send();
try {
sTXT = oXML.ResponseText;
} catch(e) {
sTXT = "[" + e.Description + "]";
}
return sTXT;
}
 
R

Rose Chambers

McKirahan said:

Will this help? Watch for word-wrap.
<--snip-->
function fetch(sURL) {
var sTXT = "";
var oXML = new ActiveXObject("Microsoft.XMLHTTP");
oXML.Open("GET",sURL,false);
oXML.send();
try {
sTXT = oXML.ResponseText;
} catch(e) {
sTXT = "[" + e.Description + "]";
}
return sTXT;
}
Did you test it in anything other than IE?
The group FAQ covers this very thing.

Which section? Honest, I did check the FAQ. All I found was
section "4.3 -- How can I access the client-side filesystem?"

Eventhough I need to access the server-side, I followed the link to
http://msdn.microsoft.com/library/en-us/script56/html/jsobjFileSystem.asp
which gives a JScript example of creating/writing on the local drive.

I didn't see anything like McKirahan's example, which also showed
how to use <SPAN>.

I would rather not use ActiveX, since it is often disabled. And
I would really prefer something that worked with more than IE.
But I appreciate any help, I'm a complete newbe.

Thanks
 
P

pennig

Which section? Honest, I did check the FAQ. All I found was
section "4.3 -- How can I access the client-side filesystem?"

Eventhough I need to access the server-side, I followed the link to
http://msdn.microsoft.com/library/en-us/script56/html/jsobjFileSystem.asp
which gives a JScript example of creating/writing on the local drive.

I didn't see anything like McKirahan's example, which also showed
how to use <SPAN>.

I would rather not use ActiveX, since it is often disabled. And
I would really prefer something that worked with more than IE.
But I appreciate any help, I'm a complete newbe.

Thanks
http://jibbering.com/2002/4/httprequest.html
Try that. It explains how to use the XMLHttpRequest object, and also
gives an example on how to incorporate the ActiveX (blech) method.
 
R

Randy Webb

Rose said:
Which section? Honest, I did check the FAQ. All I found was
section "4.3 -- How can I access the client-side filesystem?"

4.34 although the wording is elusive.

<FAQENTRY>
Why does 4.34 no longer mention reading files from a server?
Eventhough I need to access the server-side, I followed the link to
http://msdn.microsoft.com/library/en-us/script56/html/jsobjFileSystem.asp
which gives a JScript example of creating/writing on the local drive.

I didn't see anything like McKirahan's example, which also showed
how to use <SPAN>.

McKirahan's "solution" also lacked the ability to work in any browser
other than IE. Thats the problem with the example.
I would rather not use ActiveX, since it is often disabled.

So is script, so are you going to forego scripting also?
And I would really prefer something that worked with more than IE.

The HTTPRequest Object works with more than IE. Just not the way the
example was written. The page that the FAQ links to in Sec 4.34 explains
how to use it, and in a cross-browser way.
 
R

Ron Beitel

McKirahan wrote:

function fetch(sURL) {
var sTXT = "";
var oXML = new ActiveXObject("Microsoft.XMLHTTP");
oXML.Open("GET",sURL,false);
oXML.send();
try {
sTXT = oXML.ResponseText;
} catch(e) {
sTXT = "[" + e.Description + "]";
}
return sTXT;
}

<--snip-->

I would rather not use ActiveX, since it is often disabled. And
I would really prefer something that worked with more than IE.


I tested this with IE6, Netscape7.1, FireFox0.9 and Mozilla1.01(linux)

<html><head>
<title>swap_text.html</title>
<script type="text/javascript">

function display_dataset(dset) {
document.images.swap_grph.src = "/graphs/"+dset+".jpg";
document.getElementById("swap_text").src = "/textfiles/"+dset+".txt";
}

</script>
</head>
<body onload="display_dataset('data1')">

<table>
<tr><td>
<img name="swap_grph" src = "">
</td></tr>
<tr><td>
<iframe id="swap_text" src = "" WIDTH=500 HEIGHT=300></iframe>
</td></tr>
<tr><td>
<form>
<input type="button" value="One" onclick="display_dataset('data1')"/>
<input type="button" value="Two" onclick="display_dataset('data2')"/>
<input type="button" value="Three" onclick="display_dataset('data3')"/>
<input type="button" value="Four" onclick="display_dataset('data4')"/>
<input type="button" value="Five" onclick="display_dataset('data5')"/>
</form>
</td></tr>
</table>

</body></html>

I would give the chart and data table files the same name. Instead of
piechart1.jpg and data_table1.txt, rename them data1.jpg and data1.txt

If this is not possible change the function to accept two parameters, so
you can call it with explicit filenames...
onclick="display_dataset('piechart1.jpg','data_table1.txt')"
 
R

Ron Beitel

I tested this with IE6, Netscape7.1, FireFox0.9 and Mozilla1.01(linux)

<html><head>
<title>swap_text.html</title>
<script type="text/javascript">

function display_dataset(dset) {
document.images.swap_grph.src = "/graphs/"+dset+".jpg";
document.getElementById("swap_text").src = "/textfiles/"+dset+".txt";
}

</script>
</head>
<body onload="display_dataset('data1')">

<table>
<tr><td>
<img name="swap_grph" src = "">
</td></tr>
<tr><td>
<iframe id="swap_text" src = "" WIDTH=500 HEIGHT=300></iframe>
</td></tr>
<tr><td>
<form>
<input type="button" value="One" onclick="display_dataset('data1')"/>
<input type="button" value="Two" onclick="display_dataset('data2')"/>
<input type="button" value="Three" onclick="display_dataset('data3')"/>
<input type="button" value="Four" onclick="display_dataset('data4')"/>
<input type="button" value="Five" onclick="display_dataset('data5')"/>
</form>
</td></tr>
</table>

</body></html>

I would give the chart and data table files the same name. Instead of
piechart1.jpg and data_table1.txt, rename them data1.jpg and data1.txt

If this is not possible change the function to accept two parameters, so
you can call it with explicit filenames...
onclick="display_dataset('piechart1.jpg','data_table1.txt')"

Problem! Each time a new <iframe> loads, it is a new page. So the brower's
BACK button shows the previous data table, but the graph does not change.

Anyone have any suggestions?
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top