SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Oct 2003
    Location
    West Chester, PA
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Insert Content into HTML template

    ok so i know nothing about javascript yet so bear with me...

    i am looking for some way to have an external .js file that someone can easily make changes to the variables...like a form kinda thingy...that will contain multiple variables worth of info. something like having an external file info.js with something like the following inside:


    var address1 = "123 Main Street";
    var city = "anytown";
    var state = "ST";
    var zip = "12345"

    etc..

    and then in the .html file call that info.js in the head and then be able to place the individual variables separately where ever i want in the body...like calling those variables from the external file info.js

    like i said i have almost NO experience with JS but i cant imagine that this is too hard...what do yall think?

    i would greaaaatly appreciate any ideas/suggestions/code/etc.

    thanks
    Last edited by CliffHanger9; Oct 22, 2003 at 12:59. Reason: ok this has got to b easy...?...its basically writing a variable from an external .js file to an html doc...

  2. #2
    Formerly known as RockNRollPig Shpigford's Avatar
    Join Date
    Dec 2002
    Location
    Denver, CO
    Posts
    2,877
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    do you have access to PHP/MySQL? that would be much easier, faster, and more accessible on everyone's computer...

  3. #3
    SitePoint Member
    Join Date
    Oct 2003
    Location
    West Chester, PA
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nope...dont know enough sql or php for that (those technologies arent available in this scenario)...its nothing worth getting that complicated over anyway...i mean i know u said it would be easier but...all i m asking for is how do u write predefined variables in an HTML file?

    remember...i have hardly any knowledge of JS...yet.

  4. #4
    Formerly known as RockNRollPig Shpigford's Avatar
    Join Date
    Dec 2002
    Location
    Denver, CO
    Posts
    2,877
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay...well sql and php are way easier to learn than javascript...and for all functionality purposes is more popular now than javascript...anywho...with that being said...have you checked out any javascript resource sites? a lot of them have tons of code snippets that you can just copy and paste and i'm sure there is probably something to suite your needs.

  5. #5
    ********* Ornithologist AtomicPenguin's Avatar
    Join Date
    May 2002
    Location
    Vancouver, BC
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No problem! :-)

    Try this:

    1. Like you suggested, create a file called info.js, and put it on your variable contents:
    Code:
    var address1 = "123 Main Street";
    var city = "anytown";
    var state = "ST";
    var zip = "12345"
    2. In the page(s) where you want to call those variables, stick this somewhere in the <head></head>:
    Code:
    <script type="text/javascript" src="info.js"></script>
    That will pull in the info file into your page. (You'll need include the path, if it's not in the same directory).

    3. Now, in your HTML page (wherever you want those variable contents to appear) you'll need to put this:
    Code:
    <script type="text/javascript">
    document.write(nameOfVariable);
    </script>
    (Where 'nameOfVariable' is, well, the name of the variable :-)

    Hope that helps.

  6. #6
    SitePoint Member
    Join Date
    Oct 2003
    Location
    West Chester, PA
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that rocks!

    but another quickie...

    can i put HTML in for the values of the variables...

    like if i want to format some of the content that i will be putting in the external .js file???

    that would make my day!

    ROCK ON!!

    thanks again!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •