dcsimg
www.webdeveloper.com
Results 1 to 5 of 5

Thread: Max - Newbee - help display word in html - (probably super easy)

  1. #1
    Join Date
    Jun 2012
    Posts
    3

    Question Max - Newbee - help display word in html - (probably super easy)

    Hello

    My name is Max and I'm just learning Javascript and I'm stuck

    I have a .txt file called maxcode.js that reads as follows:

    var chameleon = "blue";
    Var Weight = 1;

    I have a file called about.html which has the following code in the head section:

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

    In the body section of about.html I have the following code that does not work:

    <script language="JavaScript">
    <!-- hide from older browser
    document.write(chameleon)
    //-->
    </script>

    What do I need to alter in my code so that the word blue is displayed in the web page per my variable?


    Thanks so much

    Max

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,671
    put this script in the head and pls stop flooding the forum with duplicated questions thanks in advance

  3. #3
    Join Date
    Sep 2008
    Location
    Akron, OH
    Posts
    1,143
    "I have a .txt file called maxcode.js that reads as follows:"

    Why do you say it's a .txt file? If it has the .txt extension on the file, remove it.

  4. #4
    Join Date
    Jun 2012
    Posts
    3
    Sorry for the duplicate post – as a newbee my first post here took longer to post than normal .

    All I’m trying to understand in this post is what code is needed in the body section of about.html to display a variable and in this example the variable chameleon = blue so lets say in the body section of about I want a sentence to read “The bird is blue” if the variable chameleon was red then the sentence would read “The bird is red”. If document.write is not the best code to do this – what is?

    Thank You - Max

  5. #5
    Join Date
    Sep 2008
    Location
    Akron, OH
    Posts
    1,143
    So the document.write is working? You're just looking for a better way?

    A common way is to inject it into the DOM dynamically. Ex:

    http://jsfiddle.net/D2YV3/

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles