Getting data from a text file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jean-Marie Delapierre

    Getting data from a text file

    Hi,

    I have two files in a directory.
    one called toto.txt with the following content :
    1
    2
    3
    4
    5

    one called toto.html in which I want to get the data of toto.txt with a
    javascript script.

    May you suggest me an example of a script doing this ?

    Regards.

    Jean-Marie
  • alu

    #2
    Re: Getting data from a text file

    if the data file does not necessarily need to have a .txt extension, it
    would be better to rename it toto.js (you can still open it in notepad)

    within toto.js you'll need to assign variables for the data,
    for example in the simplest way:

    mydata1 = 1
    mydata2 = 2
    mydata3 = 3
    mydata4 = 4
    mydata5 = 5


    then it's just a matter of including & using the variables within toto.html,
    for example:

    <script src="toto.js" type="text/javascript"></script>

    <script Language='JavaS cript'>
    document.write( mydata1)
    </script>


    if you must have the data in a .txt extension file, it may still work:

    <script src="toto.txt" type="text/javascript"></script>

    <script Language='JavaS cript'>
    document.write( mydata1)
    </script>

    ----------------------------------------------------------------------------

    "Jean-Marie Delapierre" <jean-marie-delapierre@wana doo.fr> wrote in message
    news:pan.2003.1 0.10.21.03.24.9 11600@wanadoo.f r...[color=blue]
    > Hi,
    >
    > I have two files in a directory.
    > one called toto.txt with the following content :
    > 1
    > 2
    > 3
    > 4
    > 5
    >
    > one called toto.html in which I want to get the data of toto.txt with a
    > javascript script.
    >
    > May you suggest me an example of a script doing this ?
    >
    > Regards.
    >
    > Jean-Marie[/color]



    Comment

    • Jean-Marie Delapierre

      #3
      Re: Getting data from a text file

      Le Fri, 10 Oct 2003 18:37:38 -0400, alu a écrit :
      [color=blue]
      > if the data file does not necessarily need to have a .txt extension, it
      > would be better to rename it toto.js (you can still open it in notepad)
      >
      > within toto.js you'll need to assign variables for the data,
      > for example in the simplest way:
      >
      > mydata1 = 1
      > mydata2 = 2
      > mydata3 = 3
      > mydata4 = 4
      > mydata5 = 5
      >
      >
      > then it's just a matter of including & using the variables within toto.html,
      > for example:
      >
      > <script src="toto.js" type="text/javascript"></script>
      >
      > <script Language='JavaS cript'>
      > document.write( mydata1)
      > </script>
      >
      >
      > if you must have the data in a .txt extension file, it may still work:
      >
      > <script src="toto.txt" type="text/javascript"></script>
      >
      > <script Language='JavaS cript'>
      > document.write( mydata1)
      > </script>
      >
      > ----------------------------------------------------------------------------
      >
      > "Jean-Marie Delapierre" <jean-marie-delapierre@wana doo.fr> wrote in message
      > news:pan.2003.1 0.10.21.03.24.9 11600@wanadoo.f r...[color=green]
      >> Hi,
      >>
      >> I have two files in a directory.
      >> one called toto.txt with the following content :
      >> 1
      >> 2
      >> 3
      >> 4
      >> 5
      >>
      >> one called toto.html in which I want to get the data of toto.txt with a
      >> javascript script.
      >>
      >> May you suggest me an example of a script doing this ?
      >>
      >> Regards.
      >>
      >> Jean-Marie[/color][/color]

      Hi,

      Thank you very mutch for your answer.
      But, your solution can't work for me. The text file (here is only a basic
      exemple) will be generated by an Excel extract.
      Therefore, I have no possibility to transform it into a javascript script
      assigning data to variables.

      Regards.

      Jean-Marie

      Comment

      • Laurent Bugnion, GalaSoft

        #4
        Re: Getting data from a text file

        Hi,

        Jean-Marie Delapierre wrote:[color=blue][color=green]
        >>
        >>"Jean-Marie Delapierre" <jean-marie-delapierre@wana doo.fr> wrote in message
        >>news:pan.2003 .10.10.21.03.24 .911600@wanadoo .fr...
        >>[color=darkred]
        >>>Hi,
        >>>
        >>>I have two files in a directory.
        >>>one called toto.txt with the following content :
        >>>1
        >>>2
        >>>3
        >>>4
        >>>5
        >>>
        >>>one called toto.html in which I want to get the data of toto.txt with a
        >>>javascript script.
        >>>
        >>>May you suggest me an example of a script doing this ?
        >>>
        >>>Regards.
        >>>
        >>>Jean-Marie[/color][/color]
        >
        >
        > Hi,
        >
        > Thank you very mutch for your answer.
        > But, your solution can't work for me. The text file (here is only a basic
        > exemple) will be generated by an Excel extract.
        > Therefore, I have no possibility to transform it into a javascript script
        > assigning data to variables.
        >
        > Regards.
        >
        > Jean-Marie[/color]

        I assume that you have access to the Excel file. If so, why not simply
        make a VB macro saving the text file in any format you decide?

        If you really don't have this possibility, one possible way is to have a
        Java applet read the text file, and pass the content to JS for
        processing. See examples and a free download at


        Other ways include (if the application runs locally only) using the
        FileSystemObjec t (IE only) or directly accessing the java File object
        (Netscape only). All these solutions need lower security settings, and
        not very easy to put in place.

        I would try the macro solution first.

        HTH,

        Laurent
        --
        Laurent Bugnion, GalaSoft
        Webdesign, Java, JavaScript: http://www.galasoft-LB.ch
        Private/Malaysia: http://mypage.bluewin.ch/lbugnion
        Support children in Calcutta: http://www.calcutta-espoir.ch

        Comment

        • alu

          #5
          Re: Getting data from a text file


          "Laurent Bugnion, GalaSoft" <galasoft-LB@bluewin_NO_S PAM.ch> wrote in
          message news:3f87b7a8$1 _4@news.bluewin .ch...[color=blue]
          > Hi,
          >
          > Jean-Marie Delapierre wrote:[color=green][color=darkred]
          > >>
          > >>"Jean-Marie Delapierre" <jean-marie-delapierre@wana doo.fr> wrote in[/color][/color][/color]
          message[color=blue][color=green][color=darkred]
          > >>news:pan.2003 .10.10.21.03.24 .911600@wanadoo .fr...
          > >>
          > >>>Hi,
          > >>>
          > >>>I have two files in a directory.
          > >>>one called toto.txt with the following content :
          > >>>1
          > >>>2
          > >>>3
          > >>>4
          > >>>5
          > >>>
          > >>>one called toto.html in which I want to get the data of toto.txt with a
          > >>>javascript script.
          > >>>
          > >>>May you suggest me an example of a script doing this ?
          > >>>
          > >>>Regards.
          > >>>
          > >>>Jean-Marie[/color]
          > >
          > >
          > > Hi,
          > >
          > > Thank you very mutch for your answer.
          > > But, your solution can't work for me. The text file (here is only a[/color][/color]
          basic[color=blue][color=green]
          > > exemple) will be generated by an Excel extract.
          > > Therefore, I have no possibility to transform it into a javascript[/color][/color]
          script[color=blue][color=green]
          > > assigning data to variables.
          > >
          > > Regards.
          > >
          > > Jean-Marie[/color]
          >
          > I assume that you have access to the Excel file. If so, why not simply
          > make a VB macro saving the text file in any format you decide?
          >
          > If you really don't have this possibility, one possible way is to have a
          > Java applet read the text file, and pass the content to JS for
          > processing. See examples and a free download at
          > http://www.galasoft-LB.ch/myjava/Web...Demo/Demo.html
          >
          > Other ways include (if the application runs locally only) using the
          > FileSystemObjec t (IE only) or directly accessing the java File object
          > (Netscape only). All these solutions need lower security settings, and
          > not very easy to put in place.
          >
          > I would try the macro solution first.
          >
          > HTH,
          >
          > Laurent
          > --[/color]


          I agree, the Excel solution should be easy.
          I'm not very familiar with Excel, but i would think that just adding 2
          columns
          to the left of the required data and then extracting all three columns
          would do the trick.
          e.g.,

          ="mydata"&RO W() = [data to extract]



          Comment

          Working...