Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / December 2004



Tip: Looking for answers? Try searching our database.

Please help with reading from a textfile on webserver

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rose Chambers - 29 Dec 2004 19:18 GMT
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.
McKirahan - 29 Dec 2004 20:04 GMT
> 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
[quoted text clipped - 16 lines]
> <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>".
Rose Chambers - 29 Dec 2004 22:33 GMT
>Will this help?  

<snip>

Yes!  Thanks so much.
Randy Webb - 29 Dec 2004 22:52 GMT
<--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 = "";
[quoted text clipped - 8 lines]
>     return sTXT;
> }

Signature

Randy
comp.lang.javascript FAQ - http://jibbering.com/faq

Rose Chambers - 30 Dec 2004 02:32 GMT
><--snip-->
>
>> Will this help?  Watch for word-wrap.
>
><--snip-->

>> function fetch(sURL) {
>>     var sTXT = "";
[quoted text clipped - 8 lines]
>>     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
pennig@gmail.com - 30 Dec 2004 14:50 GMT
> 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.
>
[quoted text clipped - 6 lines]
>
> 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.
Randy Webb - 30 Dec 2004 21:54 GMT
<--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-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.
Signature

Randy
comp.lang.javascript FAQ - http://jibbering.com/faq

Ron Beitel - 30 Dec 2004 23:16 GMT
>><--snip-->
>>
[quoted text clipped - 15 lines]
>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')"
Ron Beitel - 31 Dec 2004 05:16 GMT
>I tested this with IE6, Netscape7.1, FireFox0.9 and Mozilla1.01(linux)
>
[quoted text clipped - 37 lines]
>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?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.