FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


JS Random Include txt-File





loveandormoney
Good morning.
Maybe somebody knows a script in Javasript
which helps me to do something special.

Imagine there is a page called a.htm.
There is a table:

table tr td
and there is space for 20 words in the table.

And there are 20 files
1.txt
2.txt
3.txt
4.txt
20.txt
uploaded in the same directory.

Now the user is asking for a.htm

and everytime by random he can see in this special space in the table

4.txt
tomorrow
17.txt
and so on.


Where I can find an easy script in JS, which can do this?

Regards and thank You.
Dialogist
http://www.hscripts.com/scripts/JavaScript/random-quote-generator.php
loveandormoney
Good morning. Thank You for help.
There are a lot js-tools.

Thank You.

One question more:

There are three parts:
1
CSS code

2
JS Code

3
HTML Code


Do I have to do
2 in the head
and
3 in the body
of the homepage?


Regards
Dialogist
Yes there is a lot of examples on that site and it is best to have a look through them because on second thoughts, the one I linked you to doesn't exactly satisfy your request. It loads a random quote when you click the button. What you want is a random quote on page load/page refresh. It's a similar method and can easily be modified to do that. But there is scripts on that site that might already do exactly what you need. Have a look around.

http://www.trans4mind.com/personal_development/JavaScript/newImage.htm

That might be better suited^ and you could use images (if you wanted) or text too.

CSS scripts always go in the header.*

JS scripts usually go in the header but lately optimization sites have been suggesting that you place them right before you close the body tag (to prevent block loading). I tend to ignore them as I like my js files to load before my content so the page doesn't look garbage first and then bounce in to page. Your mileage may vary. Header or before final Body tag.*

The snippets of HTML code that sites give you to use always go in between the Body tags.

*There is a difference between inline and external scripts. The ones you are given to copy and paste (if they aren't too long) should go in there. If they are long they should go in a external .css or .js file. If they are a link to the an external file, they still go in the same places but are requested differently.

Mostly everything you'll see on sites like http://www.hscripts.com/ will be small enough to paste right in.
loveandormoney
Good morning.
If there is a short js, then I am writing it in the head part at the end before the body.
If there is a long js, then I am creating an js-file, and then the code is loaded to the htm file.
The "html" code of the script is placed, where it is needed between the body-tags.
Is this right?

The css desription
I do not need.
Is this right?

I saved the two sripts
but they are not
what I am looking for.
But I shall use these scripts on another url.

Thank You for Your friendly help.
I did not study the homepage with the tools yet.

Regards
Dialogist
loveandormoney wrote:
Good morning.
If there is a short js, then I am writing it in the head part at the end before the body.
If there is a long js, then I am creating an js-file, and then the code is loaded to the htm file.
The "html" code of the script is placed, where it is needed between the body-tags.
Is this right?


This is correct.

loveandormoney wrote:

The css desription
I do not need.
Is this right?


You don't need it but if you aren't sure what it is for, it might be wise to keep it. It won't harm anything to keep it. If it is a copyright notice, you should probably keep it. Anything that is "commented out" ie: Has \\ or // *// symbols making the line dysfunctional can be removed (these lines will be a different colour in text editors to the lines that are functional).

loveandormoney wrote:

I saved the two sripts
but they are not
what I am looking for.
But I shall use these scripts on another url.

Thank You for Your friendly help.
I did not study the homepage with the tools yet.

Regards


You can get better help by posting an example of your html code with the tables and saying where you want the changing text to go.
loveandormoney
I am searching my html code with the js-script
I was using with something similar.

And then I can explain You more easy, what I am missing.

Thank You for Your help.
Dialogist
loveandormoney wrote:
I am searching my html code with the js-script
I was using with something similar.

And then I can explain You more easy, what I am missing.

Thank You for Your help.


I am saying if you copy and paste the existing html code of the page that you already had - into here, you would get better help with applying a javascript script to it, to help you to do what you have asked for.
loveandormoney
Code:

<div align="center"><center>
     <table border="0" width="749" height="82" style="border-collapse: collapse" bordercolor="#111111" cellpadding="0" cellspacing="0">
       <tr>
           <td width="488" height="82" align="center">
               <div id="txt1" style="font-family: Verdana; font-weight: bold; color: blue; width: 745; height: 12" align="center">
                  <font face="Verdana" size="2"><span style="text-align: center">Random Text Script</span></font></div><p align="center">
                 <script language="JavaScript">
<!--
  var quoteStr;
  var quoteNum;
  var quoteDis;
  var quoteLen;
  var quoteLoc;
  var quotePic;
  var quoteMax;
  var numQuote;
  var charDelay;
  var quoteDelay;
  var delayCntr;



 function funcQuote() {
   this[0] = "TXTTXT";


...


   this[28] = "TXTTXT.";
  }
  function getQuote() {
   delayCntr = delayCntr + 1;
   quoteLoc = quoteLoc - 1;
   if (delayCntr > quoteDelay) {
      delayCntr = 100;
      quoteLen = 0;
      quoteLoc = 0;
      quoteNum = Math.floor(Math.random() * numQuote);
      quoteStr = makeQuote[quoteNum];
      quoteLen = quoteStr.length;
      quoteMax= quoteStr.length;
      padQuote();
   }
  }

  function disQuote() {
   quoteLoc = quoteLoc + 1;
   if (quoteLoc > quoteMax) {
    if (delayCntr > 50) {
      delayCntr = 0;
    }
    getQuote();
   }
   quoteDis = quoteStr.substring(0, quoteLoc);
   for (var i = quoteLoc; i < quoteMax; i++){
    var charone;
    charone = quoteStr.substring(i, i + 1);
    var rdnum;
    rdnum = Math.floor(Math.random() * 57)
    quoteDis = "" + quoteDis + quotePic.substring(rdnum, rdnum + 1);
   }
  }
  function padQuote () {
   var spacePad = quoteMax - quoteStr.length;
   var frontPad = Math.floor(spacePad / 2);
   for (var i = 0; i < frontPad; i++) {
    quoteStr = " " + quoteStr;
   }
   for (var i = quoteStr.length; i < quoteMax; i++) {
    quoteStr= "" + quoteStr + " ";
   }
  }
  function loopQuote() {
   document.all.txt1.innerHTML="<span>"+quoteDis+"</span>";
   disQuote();
   setTimeout ("loopQuote();", charDelay);
  }
  function startQuote() {
   quoteStr = "";
   quoteNum = 0;
   quoteDis = "";
   quoteLen = 0;
   quoteLoc = 0;
   quotePic = "abcdefghjkmnopqrstuvwxyzABCEDEFGHJKLMNOPQRSTUVXYZ234567890";
   quoteMax = 70;
   numQuote = 29;
   delayCntr=100;
   charDelay = 500;
   quoteDelay = 5000;
   makeQuote = new funcQuote();
   getQuote();
   disQuote();
   loopQuote();
  }
//-->
                 </script> </td>
       </tr>
     </table>
     </center>
  </div>




This is a code.
But with this code
I can show only one line.

Thank You for Your help.



Related topics
Create a txt file
Wonders of the include() in PHP.
Google Adsense With Php
importing a .txt
PHP: Writing to txt file
Creating a .txt file
.txt file to .php Lined to tables
does someone have a simple "save to txt file" scri
Displaying .txt file on web page
I can't open directly .txt file on my desktop
Saving a .txt file to a ftp using vb6. i need help please
VB 6.0 need help loading a .txt file into a text box
is it possible to get a html text box to load a .txt file?
Program That Picks a Random File from Folder
Reply to topic    Frihost Forum Index -> Webmaster and Internet -> Design Tips

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.