Probably A Simple Answer...Text Display...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ChuckB via WebmasterKB.com

    Probably A Simple Answer...Text Display...

    I can't get this simple crappp!!

    Not understanding why my text isn't displaying....

    <html><head><ti tle>Problem6</title>

    <script type="text/javascript">

    var my_message="I love football";
    var my_div=document .getElementById ("space");
    my_div.innerHTM L(my_message);

    </script>
    <style type="text/css">

    #space{position :absolute; left:10px; top:20px;}

    #mybuttons{posi tion:absolute; left:10px; top:75px;}

    </style></head>
    <body>
    <div id="space">
    </div>
    <div id = "mybuttons" >
    <input type="button" value="startscr oll" id="start">
    <input type="button" value="stopscro ll" id="stop">
    </div>

    </body>
    </html>

    --
    Message posted via http://www.webmasterkb.com

  • Tim Williams

    #2
    Re: Probably A Simple Answer...Text Display...

    my_div.innerHTM L = my_message;

    Tim

    "ChuckB via WebmasterKB.com " <u46201@uwewrot e in message
    news:8ad8274b0a eae@uwe...
    >I can't get this simple crappp!!
    >
    Not understanding why my text isn't displaying....
    >
    <html><head><ti tle>Problem6</title>
    >
    <script type="text/javascript">
    >
    var my_message="I love football";
    var my_div=document .getElementById ("space");
    my_div.innerHTM L(my_message);
    >
    </script>
    <style type="text/css">
    >
    #space{position :absolute; left:10px; top:20px;}
    >
    #mybuttons{posi tion:absolute; left:10px; top:75px;}
    >
    </style></head>
    <body>
    <div id="space">
    </div>
    <div id = "mybuttons" >
    <input type="button" value="startscr oll" id="start">
    <input type="button" value="stopscro ll" id="stop">
    </div>
    >
    </body>
    </html>
    >
    --
    Message posted via http://www.webmasterkb.com
    >

    Comment

    • Conrad Lender

      #3
      Re: Probably A Simple Answer...Text Display...

      On 2008-09-28 03:31, Tim Williams wrote:
      my_div.innerHTM L = my_message;
      Are you sure?
      There is no element with the id "space" at this point...


      - Conrad

      Comment

      • ChuckB via WebmasterKB.com

        #4
        Re: Probably A Simple Answer...Text Display...

        Tim Williams wrote:
        >my_div.innerHT ML = my_message;
        >
        >Tim
        >
        >>I can't get this simple crappp!!
        >>
        >[quoted text clipped - 26 lines]
        ></body>
        ></html>
        Thanks for the response...trie d that...still nothing:

        <html><head><ti tle>Problem6</title>

        <script type="text/javascript">

        var my_message="I love football";
        var my_div=document .getElementById ("space");
        my_div.innerHTM L=my_message;

        </script>
        <style type="text/css">

        #space{position :absolute; left:10px; top:20px; width:200px; height:50px;
        border:1px solid black;}

        #mybuttons{posi tion:absolute; left:10px; top:75px;}

        </style></head>
        <body>
        <div id="space">
        </div>
        <div id = "mybuttons" >
        <input type="button" value="startscr oll" id="start">
        <input type="button" value="stopscro ll" id="stop">
        </div>

        </body>
        </html>

        --
        Message posted via http://www.webmasterkb.com

        Comment

        • ChuckB via WebmasterKB.com

          #5
          Re: Probably A Simple Answer...Text Display...

          Conrad Lender wrote:
          >my_div.innerHT ML = my_message;
          >
          >Are you sure?
          >There is no element with the id "space" at this point...
          >
          - Conrad
          There's the div element....

          --
          Message posted via http://www.webmasterkb.com

          Comment

          • Conrad Lender

            #6
            Re: Probably A Simple Answer...Text Display...

            On 2008-09-28 03:38, ChuckB via WebmasterKB.com wrote:
            >>There is no element with the id "space" at this point...
            >
            There's the div element....
            Where?
            13 lines after you try to access it?

            The element has to exist before you can "get it by ID".


            - Conrad

            Comment

            • ChuckB via WebmasterKB.com

              #7
              Re: Probably A Simple Answer...Text Display...

              Conrad Lender wrote:
              >>>There is no element with the id "space" at this point...
              >>
              >There's the div element....
              >
              >Where?
              >13 lines after you try to access it?
              >
              >The element has to exist before you can "get it by ID".
              >
              - Conrad
              Right here:

              <body>
              ...
              <div id="space">
              </div>
              ...
              </body>

              Am I missing something here?

              --
              Message posted via WebmasterKB.com


              Comment

              • Ben Amada

                #8
                Re: Probably A Simple Answer...Text Display...

                ChuckB via WebmasterKB.com :
                Conrad Lender wrote:
                >>>>There is no element with the id "space" at this point...
                >>>
                >>There's the div element....
                >>
                >>Where?
                >>13 lines after you try to access it?
                >>
                >>The element has to exist before you can "get it by ID".
                >>
                > - Conrad
                >
                Right here:
                >
                <body>
                ..
                <div id="space">
                </div>
                ..
                </body>
                >
                Am I missing something here?
                Your JavaScript is running before the DIV exists. You'll want to wrap your
                code into a function and call it once the page has finished loaded. At that
                point, the DIV will exist.

                <script type="text/javascript">
                function doOnload() {
                var my_message="I love football";
                var my_div=document .getElementById ("space");
                my_div.innerHTM L(my_message);
                }
                </script>

                Then you can call this new "doOnload" function when the body has loaded:

                <body onload="doOnloa d()">

                Comment

                • Conrad Lender

                  #9
                  Re: Probably A Simple Answer...Text Display...

                  On 2008-09-28 04:28, Ben Amada wrote:
                  Your JavaScript is running before the DIV exists. You'll want to wrap your
                  code into a function and call it once the page has finished loaded. At that
                  point, the DIV will exist.
                  Exactly. But don't forget to fix the other error that Tim pointed out:
                  function doOnload() {
                  var my_message="I love football";
                  var my_div=document .getElementById ("space");
                  my_div.innerHTM L(my_message);
                  my_div.innerHTM L = my_message;

                  Strictly speaking, innerHTML isn't even necessary here (and it's a
                  proprietary property). "mydiv.firstChi ld.data = my_message" will do just
                  fine in this simple case.


                  - Conrad

                  Comment

                  • ChuckB via WebmasterKB.com

                    #10
                    Re: Probably A Simple Answer...Text Display...

                    Conrad Lender wrote:
                    >Your JavaScript is running before the DIV exists. You'll want to wrap your
                    >code into a function and call it once the page has finished loaded. At that
                    >point, the DIV will exist.
                    >
                    >Exactly. But don't forget to fix the other error that Tim pointed out:
                    >
                    >function doOnload() {
                    > var my_message="I love football";
                    > var my_div=document .getElementById ("space");
                    > my_div.innerHTM L(my_message);
                    >
                    >my_div.innerHT ML = my_message;
                    >
                    >Strictly speaking, innerHTML isn't even necessary here (and it's a
                    >proprietary property). "mydiv.firstChi ld.data = my_message" will do just
                    >fine in this simple case.
                    >
                    - Conrad
                    Got it...Lesson learned...alway s call JavaScript code with a function or else
                    it will execute before the html appears.

                    I think that's the lesson....

                    --
                    Message posted via WebmasterKB.com


                    Comment

                    • Conrad Lender

                      #11
                      Re: Probably A Simple Answer...Text Display...

                      On 2008-09-28 04:45, ChuckB via WebmasterKB.com wrote:
                      Got it...Lesson learned...alway s call JavaScript code with a function or else
                      it will execute before the html appears.
                      >
                      I think that's the lesson....
                      Almost, but not quite. Take this case:

                      <script type="text/javascript">
                      function insertMyText () {
                      var my_div = document.getEle mentById("space ");
                      my_div.innerHTM L = "I love football";
                      }
                      insertMyText();
                      </script>
                      <div id="space"</div>

                      That will still give you an error, even though your code was executed in
                      a function. This however will work fine:

                      <div id="space"</div>
                      <script type="text/javascript">
                      var my_div = document.getEle mentById("space ");
                      my_div.innerHTM L = "I love football";
                      </script>

                      The point is that you can only access elements (by ID or otherwise)
                      after they have been "seen" by the scripting engine (which, like us,
                      reads the document from top to bottom). To be absolutely sure that all
                      elements are ready, you can wait until the "load" event. That's what Ben
                      did when he called his function from the body element's "onload" attribute.


                      - Conrad

                      Comment

                      • ChuckB via WebmasterKB.com

                        #12
                        Re: Probably A Simple Answer...Text Display...

                        Conrad Lender wrote:
                        >Got it...Lesson learned...alway s call JavaScript code with a function or else
                        >it will execute before the html appears.
                        >>
                        >I think that's the lesson....
                        >
                        >Almost, but not quite. Take this case:
                        >
                        ><script type="text/javascript">
                        >function insertMyText () {
                        var my_div = document.getEle mentById("space ");
                        my_div.innerHTM L = "I love football";
                        >}
                        >insertMyText() ;
                        ></script>
                        ><div id="space"</div>
                        >
                        >That will still give you an error, even though your code was executed in
                        >a function. This however will work fine:
                        >
                        ><div id="space"</div>
                        ><script type="text/javascript">
                        >var my_div = document.getEle mentById("space ");
                        >my_div.innerHT ML = "I love football";
                        ></script>
                        >
                        >The point is that you can only access elements (by ID or otherwise)
                        >after they have been "seen" by the scripting engine (which, like us,
                        >reads the document from top to bottom). To be absolutely sure that all
                        >elements are ready, you can wait until the "load" event. That's what Ben
                        >did when he called his function from the body element's "onload" attribute.
                        >
                        - Conrad
                        Okay, got it...now if you don't mind...please respond to the REAL problem I'm
                        having on the NEW POST. ..now that I finally got that out the way :-)

                        --
                        Message posted via WebmasterKB.com


                        Comment

                        Working...