#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Location
    brussels, belgium
    Posts
    2
    Rep Power
    0

    import name value pairs from .txt to javascript?


    hi,

    I've been doing a bit of research and still can't find the anwer... I'm feeling a bit dumb because this should be fairly straight forward....

    suppose I have a txt file called my_vars.txt containing this: name=sakri&age=27&

    is it possible to "load" or "include" it with javascript to an html page, then parse the name value pairs and then use them in a javascript???

    I do this type of thing all the time with macromedia flash, and I'd like to reuse the .txt files for a html version...

    any pointers or help is well appreciated!

    thanks

  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Posts
    35
    Rep Power
    12

    Modifying Client-Side Script with Server-Side.


    It is entirely possible to use a server-side script to modify a client-side script. I'd probably imagine something along the lines of either:

    1. In the .shtml or .asp file, call the function as

    function_name(<!--#include file="file_name"-->)
    or
    function_name(<!--#echo var="QUERY_STRING"-->)

    or

    2. declare your function thus:

    <script>
    function my_function () {
    var some_variable=<!--#include file="file_name"-->;
    ...
    ...
    ...
    ...
    }
    </script>

    The JavaScript will never see the difference between you bringing in variables this way or declaring them explicitly, and when the server parses the .shtml/.asp file for SSI directives, it will not care that it is echoing them into script rather than HTML.

    Hope this is of some use.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Location
    brussels, belgium
    Posts
    2
    Rep Power
    0
    thanks hrsdh,

    but I found a solution here:

    http://www.ashleyit.com/rs/main.htm

    this jsrs does what I wanted, load external "stuff" (xml or whatever) at any given time! neato!

IMN logo majestic logo threadwatch logo seochat tools logo