By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,503 Members | 1,143 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,503 IT Pros & Developers. It's quick & easy.

Please help with reading from a textfile on webserver

P: n/a
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.
Jul 23 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
"Rose Chambers" <no@email.com> wrote in message
news:mo********************************@4ax.com...
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>".
Jul 23 '05 #2

P: n/a
On Wed, 29 Dec 2004 20:04:24 GMT, "McKirahan" <Ne**@McKirahan.com> wrote:


Will this help?


<snip>

Yes! Thanks so much.

Jul 23 '05 #3

P: n/a
McKirahan wrote:
"Rose Chambers" <no@email.com> wrote in message
news:mo********************************@4ax.com...
<--snip-->
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;
}


--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #4

P: n/a
On Wed, 29 Dec 2004 17:52:45 -0500, Randy Webb <Hi************@aol.com> wrote:
McKirahan wrote:
"Rose Chambers" <no@email.com> wrote in message
news:mo********************************@4ax.com...
<--snip-->
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...FileSystem.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

Jul 23 '05 #5

P: n/a
> 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...FileSystem.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.

Jul 23 '05 #6

P: n/a
Rose Chambers wrote:
On Wed, 29 Dec 2004 17:52:45 -0500, Randy Webb <Hi************@aol.com> wrote:
<--snip-->
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?"


4.34 although the wording is elusive.

<FAQENTRY>
Why does 4.34 no longer mention reading files from a server?
</FAQENTRY>
Eventhough I need to access the server-side, I followed the link to
http://msdn.microsoft.com/library/en...FileSystem.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.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #7

P: n/a
On Thu, 30 Dec 2004 02:32:08 GMT, Rose Chambers <no@email.com> wrote:
On Wed, 29 Dec 2004 17:52:45 -0500, Randy Webb <Hi************@aol.com> wrote:
McKirahan wrote:

<--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;
}


<--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_tab le1.txt')"
Jul 23 '05 #8

P: n/a
On Thu, 30 Dec 2004 23:16:31 GMT, Ron Beitel <ro**@not.here> wrote:

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_tab le1.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?

Jul 23 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.