Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. JavaScript
  4. Reading a text file in JS

Reading a text file in JS

Scheduled Pinned Locked Moved JavaScript
javascriptquestion
11 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hakan Bulut
    wrote on last edited by
    #1

    Is it possible to read a text file in javascript? Sample code pls..

    L M D 3 Replies Last reply
    0
    • H Hakan Bulut

      Is it possible to read a text file in javascript? Sample code pls..

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Hakan Bulut wrote:

      Sample code pls..

      Please try to do your own research first. You can use Google, or go here[^] for help on Javascript.

      Use the best guess

      1 Reply Last reply
      0
      • H Hakan Bulut

        Is it possible to read a text file in javascript? Sample code pls..

        M Offline
        M Offline
        Manfred Rudolf Bihy
        wrote on last edited by
        #3

        Since google seems too hard to use for you I found you some links with relevant information. Now all I can wish for is that you'll study them carefully.

        1. W3C File API[^]
        2. Which browsers support File API[^]
        3. HTML5 File API Demo/[^]

        Have fun! Regards,

        — Manfred

        "I had the right to remain silent, but I didn't have the ability!"

        Ron White, Comedian

        1 Reply Last reply
        0
        • H Hakan Bulut

          Is it possible to read a text file in javascript? Sample code pls..

          D Offline
          D Offline
          dusty_dex
          wrote on last edited by
          #4

          No. not generally easy from within a web browser. It's a security risk. But you can disguise file as .js and load it with the script tag. <script language="javascript" src="file.js"></script> The file *must* contain valid script code. But you can put your data in string form, assigned to a variable. Note: the external file must not contain any script tags. direct loading of any file type is possible when using the following.. Web servers node.js spidermonkey shell rhino shell Windows Script Host (cscript)

          "It's true that hard work never killed anyone. But I figure, why take the chance." - Ronald Reagan That's what machines are for. Got a problem? Sleep on it.

          H 1 Reply Last reply
          0
          • D dusty_dex

            No. not generally easy from within a web browser. It's a security risk. But you can disguise file as .js and load it with the script tag. <script language="javascript" src="file.js"></script> The file *must* contain valid script code. But you can put your data in string form, assigned to a variable. Note: the external file must not contain any script tags. direct loading of any file type is possible when using the following.. Web servers node.js spidermonkey shell rhino shell Windows Script Host (cscript)

            "It's true that hard work never killed anyone. But I figure, why take the chance." - Ronald Reagan That's what machines are for. Got a problem? Sleep on it.

            H Offline
            H Offline
            Hakan Bulut
            wrote on last edited by
            #5

            It is good idea. I have to try it :)

            D 1 Reply Last reply
            0
            • H Hakan Bulut

              It is good idea. I have to try it :)

              D Offline
              D Offline
              dusty_dex
              wrote on last edited by
              #6

              here's an example. :) This is the external file, i have called it extern.js

              this['data_array'] = [ "The quick brown fox jumped over the lazy dog.", 123, 456, "etc.." ];

              this['data_json'] = { item1 : "the quick brown fox jumped over the lazy dog.",
              item2 : 123, item3 : 456,
              item4 : "etc.."
              }

              Code for the web page that loads it.

              <head>
              <script type="text/javascript" src="extern.js"></script>
              <script type="text/javascript">
              function dw(s) { var s = s || ""; document.write(s + "
              "); }

              var i = 0;

              while (i < data_array.length) {
              dw(data_array[i]);
              i++;
              }

              dw();
              dw("item1. "+ data_json.item1);
              dw("item2. "+ data_json.item2);
              dw("item3. "+ data_json.item3);
              dw("item4. "+ data_json.item4);

              </script>
              </head>
              <body>
              </body>
              </html>

              "It's true that hard work never killed anyone. But I figure, why take the chance." - Ronald Reagan That's what machines are for. Got a problem? Sleep on it.

              H 2 Replies Last reply
              0
              • D dusty_dex

                here's an example. :) This is the external file, i have called it extern.js

                this['data_array'] = [ "The quick brown fox jumped over the lazy dog.", 123, 456, "etc.." ];

                this['data_json'] = { item1 : "the quick brown fox jumped over the lazy dog.",
                item2 : 123, item3 : 456,
                item4 : "etc.."
                }

                Code for the web page that loads it.

                <head>
                <script type="text/javascript" src="extern.js"></script>
                <script type="text/javascript">
                function dw(s) { var s = s || ""; document.write(s + "
                "); }

                var i = 0;

                while (i < data_array.length) {
                dw(data_array[i]);
                i++;
                }

                dw();
                dw("item1. "+ data_json.item1);
                dw("item2. "+ data_json.item2);
                dw("item3. "+ data_json.item3);
                dw("item4. "+ data_json.item4);

                </script>
                </head>
                <body>
                </body>
                </html>

                "It's true that hard work never killed anyone. But I figure, why take the chance." - Ronald Reagan That's what machines are for. Got a problem? Sleep on it.

                H Offline
                H Offline
                Hakan Bulut
                wrote on last edited by
                #7

                This is really great sample thx.

                1 Reply Last reply
                0
                • D dusty_dex

                  here's an example. :) This is the external file, i have called it extern.js

                  this['data_array'] = [ "The quick brown fox jumped over the lazy dog.", 123, 456, "etc.." ];

                  this['data_json'] = { item1 : "the quick brown fox jumped over the lazy dog.",
                  item2 : 123, item3 : 456,
                  item4 : "etc.."
                  }

                  Code for the web page that loads it.

                  <head>
                  <script type="text/javascript" src="extern.js"></script>
                  <script type="text/javascript">
                  function dw(s) { var s = s || ""; document.write(s + "
                  "); }

                  var i = 0;

                  while (i < data_array.length) {
                  dw(data_array[i]);
                  i++;
                  }

                  dw();
                  dw("item1. "+ data_json.item1);
                  dw("item2. "+ data_json.item2);
                  dw("item3. "+ data_json.item3);
                  dw("item4. "+ data_json.item4);

                  </script>
                  </head>
                  <body>
                  </body>
                  </html>

                  "It's true that hard work never killed anyone. But I figure, why take the chance." - Ronald Reagan That's what machines are for. Got a problem? Sleep on it.

                  H Offline
                  H Offline
                  Hakan Bulut
                  wrote on last edited by
                  #8

                  In actually I'm woking on the lottery picker script .. I have job experience in the past for that bit of luck lotto combination now i want to make a scripting. I want to make the anatomy of the program combination lottery's anatomy is as follows: Lucky numbers in the last week and the previous week each one between and each other once the lucky lottery numbers, which will be played the week after the coupon is fixed or randomly selected from the remaining numbers in arithmetical or mathematical and two column of the week that determines the coupon. Weekly 6/49 lotto ----------------- x1,x2,x3,x4,x5,x6 - Previous week x1,x2,x3,x4,x5,x6 - Last Week Forexample: x2 and x4 numbers are lucky pick numbers that up to up for two weekly score. (-- random or arith. math reslt) 1. Column : --,x2,--,x4,--,-- 2. Column : --,x2,--,x4,--,-- At first, the program or script should find out the lucky numbers in two weekly score and finally take it to me to 2 cloumn result.

                  D 1 Reply Last reply
                  0
                  • H Hakan Bulut

                    In actually I'm woking on the lottery picker script .. I have job experience in the past for that bit of luck lotto combination now i want to make a scripting. I want to make the anatomy of the program combination lottery's anatomy is as follows: Lucky numbers in the last week and the previous week each one between and each other once the lucky lottery numbers, which will be played the week after the coupon is fixed or randomly selected from the remaining numbers in arithmetical or mathematical and two column of the week that determines the coupon. Weekly 6/49 lotto ----------------- x1,x2,x3,x4,x5,x6 - Previous week x1,x2,x3,x4,x5,x6 - Last Week Forexample: x2 and x4 numbers are lucky pick numbers that up to up for two weekly score. (-- random or arith. math reslt) 1. Column : --,x2,--,x4,--,-- 2. Column : --,x2,--,x4,--,-- At first, the program or script should find out the lucky numbers in two weekly score and finally take it to me to 2 cloumn result.

                    D Offline
                    D Offline
                    dusty_dex
                    wrote on last edited by
                    #9

                    Sorry, it is very hard to understand you. Please delete your message, and start with a new thread. Try and provide example code, or just the general flow done with comments on separate lines like below. It will help you figure out what order to do things, and should help you explain it better on Code Project.

                    // Select lucky number(s) from last week (current_week -1)

                    // Select lucky number(s) from previous week (current_week -2)

                    // do this, *IF* *ELSE*

                    // do that, *IF* *ELSE*

                    .
                    .
                    .

                    Include *any* old code you have written that you are wanting to redo in javascript.

                    "It's true that hard work never killed anyone. But I figure, why take the chance." - Ronald Reagan That's what machines are for. Got a problem? Sleep on it.

                    H 1 Reply Last reply
                    0
                    • D dusty_dex

                      Sorry, it is very hard to understand you. Please delete your message, and start with a new thread. Try and provide example code, or just the general flow done with comments on separate lines like below. It will help you figure out what order to do things, and should help you explain it better on Code Project.

                      // Select lucky number(s) from last week (current_week -1)

                      // Select lucky number(s) from previous week (current_week -2)

                      // do this, *IF* *ELSE*

                      // do that, *IF* *ELSE*

                      .
                      .
                      .

                      Include *any* old code you have written that you are wanting to redo in javascript.

                      "It's true that hard work never killed anyone. But I figure, why take the chance." - Ronald Reagan That's what machines are for. Got a problem? Sleep on it.

                      H Offline
                      H Offline
                      Hakan Bulut
                      wrote on last edited by
                      #10

                      There is no code in my explain. week1 array week2 array After comparison of all elements in the array of 12 elements, the numbers 1-2-3 came time to play the next week swings are fixed and others.

                      D 1 Reply Last reply
                      0
                      • H Hakan Bulut

                        There is no code in my explain. week1 array week2 array After comparison of all elements in the array of 12 elements, the numbers 1-2-3 came time to play the next week swings are fixed and others.

                        D Offline
                        D Offline
                        dusty_dex
                        wrote on last edited by
                        #11

                        Yes. but I have no idea how your lottery system works. Your explanation is almost impossible to understand without some more detail. Or some code. ;) I want to help you. Q1. how do you decide when the random lucky numbers are produced instead of using previous ones? Q2. Are the new lottery number + lucky numbers produced (automatically) based on current Date & Time? I've done similar stuff a very long time ago, written in BASIC.

                        "It's true that hard work never killed anyone. But I figure, why take the chance." - Ronald Reagan That's what machines are for. Got a problem? Sleep on it.

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups