Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I want to print text from a documen

Status
Not open for further replies.

gns100

Programmer
Aug 11, 2003
40
US
I want to print text from a document identified in a JS function (myText_1.txt below) by transferring it to the <body> section where it will be shown on the website. The text is comments that go with a slide show.

Here is code that I have used in the past to transfer a string. I simply want to replace the string part with the text document. However, what I have tried so far doesn't work.

Anyone out there familiar with this. It should be straight forward but somehow, I'm missing something.

Look at the code near the bottom to see where the myText_1.txt file is introduced.

Thanks

Code:
<html>

<head>
<title>none</title>

<script language=&quot;JavaScript&quot; type=&quot;text/JavaScript&quot;>
<!-- Hide from browsers that do not support JavaScript

var timerId = setInterval(&quot;timedPhoto()&quot;, 2*1000)
last = 4

var viewRandom = 0
var viewCycle = 10
var photoNum = 0

// -->
</script>

</head>

<body bgcolor=&quot;#FF9900&quot;>

<table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse: collapse&quot; bordercolor=&quot;#111111&quot; width=&quot;579&quot; height=&quot;158&quot;>
  <tr>
    <td width=&quot;373&quot; height=&quot;60&quot; bgcolor=&quot;#FFFF99&quot;>
    <p style=&quot;margin-left: 9; margin-right: 9&quot; align=&quot;center&quot;><br>
    <b><font face=&quot;Arial&quot; size=&quot;5&quot; color=&quot;#0000FF&quot;>Local</font></b></p>
    <p style=&quot;margin-left: 9; margin-right: 9&quot;>
    <font lang=&quot;0&quot; face=&quot;Arial&quot; size=&quot;2&quot; FAMILY=&quot;SANSSERIF&quot;>&nbsp;</font></p>
    <p style=&quot;margin-left: 9; margin-right: 9&quot;>
    &nbsp;</p>
    <p style=&quot;margin-left: 9; margin-right: 9&quot;>
    &nbsp;</p>
    <p style=&quot;margin-left: 9; margin-right: 9&quot;>
    &nbsp;</p>
    <p style=&quot;margin-left: 9; margin-right: 9&quot;>
    <font face=&quot;Arial&quot; size=&quot;2&quot;>See one of their recent projects in the adjacent 
    photo display.</font></p>
    <p style=&quot;margin-left: 9; margin-right: 9&quot; align=&quot;center&quot;>&nbsp;</td>
    <td width=&quot;195&quot; height=&quot;158&quot; bgcolor=&quot;#FFCC66&quot; rowspan=&quot;2&quot;>
    <table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse: collapse&quot; bordercolor=&quot;#111111&quot; width=&quot;88%&quot; height=&quot;186&quot;>
      <tr>
        <td width=&quot;100%&quot; height=&quot;128&quot;>
        <p align=&quot;center&quot;>
        <img border=&quot;2&quot; src=&quot;file:///j:/myImage_1.jpg&quot; name=&quot;showPhotoRotate&quot; align=&quot;center&quot;></td>
</td>
      </tr>
      <tr>
        <td width=&quot;100%&quot; height=&quot;37&quot;><p align=&quot;center&quot;><b><font face=&quot;Arial&quot; size=&quot;3&quot;> <span id = &quot;slideText&quot;></span></font></b></td>
      </tr>
      <tr>
        <td width=&quot;100%&quot; height=&quot;21&quot;><p align=&quot;center&quot;><b><font face=&quot;Arial&quot; size=&quot;2&quot;><span id = &quot;ministryText&quot;></span></font></b></td>
      </tr>
    </table>
    </td>
  </tr>
  <tr>
    <td width=&quot;373&quot; height=&quot;70&quot; bgcolor=&quot;#FFFF99&quot;>
    <p style=&quot;margin-left: 9; margin-right: 9&quot;>&nbsp;</td>
  </tr>
</table>

</body>
<script language=&quot;JavaScript&quot; type=&quot;text/JavaScript&quot;>
<!-- Hide from browsers that do not support JavaScript
			
function timedPhoto() {
	//alert(&quot;last = &quot; + last)
	if (viewRandom == 1) {
	do {
		random1Photo = (Math.floor(Math.random() * 10) +1)
		//alert(&quot;random1Photo Number =&quot; + random1Photo)
		}
	while(last == random1Photo)
		
	last = random1Photo;
	}
	else {
		//alert(&quot;photoNum = &quot; + photoNum); 
		photoNum++;
		if(photoNum == viewCycle){
			photoNum = 1;
		}
		//alert(&quot;photoNum = &quot; + photoNum); 
		random1Photo = photoNum;
		imgNumber=random1Photo;
	}
	//}
	
			document.showPhotoRotate.src = &quot;file:///j:/myImages/image_mod_&quot; + imgNumber + &quot;.jpg&quot;
			imageText_3 = &quot;file:///j:/myText_1.txt&quot;
			document.photoText=imageText_3
			document.getElementById(&quot;slideText&quot;).innerHTML = document.photoText
			
			document.partnerText=&quot;Test2&quot;
			document.getElementById(&quot;ministryText&quot;).innerHTML = document.partnerText
}

//-->
</script>

</html>
 
string is the only way, u cannot open files in JS(normally)...

Known is handfull, Unknown is worldfull
 
Thanks vbkris.

For example, if imageText_3=&quot;THREE&quot; how do I get the contents of imageText_3 (THREE) back to the <BODY> section to display. I want to create a list (1, 2, 3 ....) of slide titles for display.
 
Code:
<html>
<body>
<script>
imageText_3=&quot;THREE&quot;
document.write(imageText_3)
</script>
</body>
</html>

Known is handfull, Unknown is worldfull
 
Thanks for your quick response.

Your code writes &quot;THREE&quot; on a new page. I want to place the text in a specific area of the slide show and am trying to move it back to the <body> area where the slides and other text is displayed. (See the code at the bottom of the initial posting).

I think all I need to know is how to move & display the contents of the document instead of the document title.
 
ur code is correct there, that is we have to use document.getElement method to do that. but now this confuses me:
>>how do I get the contents of imageText_3 (THREE) back to the <BODY> section to display

Known is handfull, Unknown is worldfull
 
vbkris:

The code I have shown displays &quot;file:///j:/myText_1.txt&quot; not the text in the file.

The following code lines I have written
Code:
            imageText_3 = &quot;file:///j:/myText_1.txt&quot;
            document.photoText=imageText_3
            document.getElementById(&quot;slideText&quot;).innerHTML = document.photoText

and the corresponding code in the <body> section

Code:
        <td width=&quot;100%&quot; height=&quot;37&quot;><p align=&quot;right&quot;><b><font face=&quot;Arial&quot; size=&quot;3&quot;> <span id = &quot;slideText&quot;></span></font></b></td>

don't do what I want and so probably the first line

Code:
imageText_3 = &quot;file:///j:/myText_1.txt&quot;

is not correct.
 
u want to display the textfile directly within an HTML? then u have to use IFRAMES only.
this is a simple tag, try embedding it:
<iframe src=&quot;txtfilepath&quot;></iframe>

Known is handfull, Unknown is worldfull
 
vbkris:

I just want to display the text (in the HTML section, on the same page) which I produce in the JS section. I don't want to create a frame.

Look at the source code above (at the original posting). The text gets generated in &quot;function timedPhoto()&quot;. I simply want to display it in the slide show, along with the image.

Using the &quot;document.getElement method&quot; I can transfer a string. I just want to know how to do the same thing using a file containing a different text for each slide.

Thanks
 
i understand ur problem, but by defalt JS has not been built for openeing files (on server or client side), therefore it will be impossible to call the file using JS thats why i had to revert to pure HTML...

Known is handfull, Unknown is worldfull
 
This a hack solution. First you create a hidden/invisible iframe which going to load image description file that you want:

<iframe style=&quot;display:none&quot; id=&quot;hframe&quot; name=&quot;hidenFrame&quot; src=&quot;#&quot;>
<div id='imageText'/>

then you use javascript to use the load the image description file and get the text from the frame.

function getImageText(url) {
document.getElementById('hframe').src=&quot;.imageDescription.txt&quot;;
document.getElementById('imageText').innerHTML = window.frames['hidenFrame'].document.body.innerHTML&quot;;
}

You will need to add some logic to detect iframe has been loaded before getting the innerHTML from it for display.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top