Can JavaScript place HTML code into Div...?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tom Szabo

    #1

    Can JavaScript place HTML code into Div...?

    Hi,

    What I like to know is if it is possible to have a JavaScript writing code
    into a DIV section, that is say during load or on a certain event in the
    same page it would insert the word "hello"

    ----------------
    .......
    <script>
    function insert_hello(){
    ?????
    }
    </script>

    <body onload="insert_ hello()"....


    <div id=div1 name=div1>
    </div>
    ....

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

    ...so it would display the word "hello" in the area taken up by the <DIV
    id=div1 name=div1>
    I understand you can change attributes/properties like the value of a text
    field but what about this scenario???


    TIA,

    Tom


  • Evertjan.

    #2
    Re: Can JavaScript place HTML code into Div...?

    Tom Szabo wrote on 16 nov 2004 in comp.lang.javas cript:[color=blue]
    > What I like to know is if it is possible to have a JavaScript writing
    > code into a DIV section, that is say during load or on a certain event
    > in the same page it would insert the word "hello"
    >
    > ----------------
    > ......
    > <script>
    > function insert_hello(){[/color]

    document.getEle mentById("div1" ).innerHTML="He llo"
    [color=blue]
    >}
    > </script>
    >
    > <body onload="insert_ hello()"....
    >
    >
    > <div id=div1 name=div1>
    > </div>
    > ...
    >
    > -----------------
    >
    > ..so it would display the word "hello" in the area taken up by the
    > <DIV id=div1 name=div1>
    > I understand you can change attributes/properties like the value of a
    > text field but what about this scenario???[/color]




    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress,
    but let us keep the discussions in the newsgroup)

    Comment

    • Tom Szabo

      #3
      Re: Can JavaScript place HTML code into Div...?

      Thanks, it does exactly what I needed,

      Thanks again,

      Tom


      "Evertjan." <exjxw.hannivoo rt@interxnl.net > wrote in message
      news:Xns95A3ADA A3F1E7eejj99@19 4.109.133.29...[color=blue]
      > Tom Szabo wrote on 16 nov 2004 in comp.lang.javas cript:[color=green]
      > > What I like to know is if it is possible to have a JavaScript writing
      > > code into a DIV section, that is say during load or on a certain event
      > > in the same page it would insert the word "hello"
      > >
      > > ----------------
      > > ......
      > > <script>
      > > function insert_hello(){[/color]
      >
      > document.getEle mentById("div1" ).innerHTML="He llo"
      >[color=green]
      > >}
      > > </script>
      > >
      > > <body onload="insert_ hello()"....
      > >
      > >
      > > <div id=div1 name=div1>
      > > </div>
      > > ...
      > >
      > > -----------------
      > >
      > > ..so it would display the word "hello" in the area taken up by the
      > > <DIV id=div1 name=div1>
      > > I understand you can change attributes/properties like the value of a
      > > text field but what about this scenario???[/color]
      >
      >
      >
      >
      > --
      > Evertjan.
      > The Netherlands.
      > (Please change the x'es to dots in my emailaddress,
      > but let us keep the discussions in the newsgroup)
      >[/color]


      Comment

      • Dr John Stockton

        #4
        Re: Can JavaScript place HTML code into Div...?

        JRS: In article <419a323b@dnews .tpgi.com.au>, dated Wed, 17 Nov 2004
        02:50:20, seen in news:comp.lang. javascript, Tom Szabo
        <tom@intersoft. net.au> posted :

        Please place responses after trimmed quotes - see newsgroup FAQ, 2.3.
        [color=blue]
        >Thanks, it does exactly what I needed,[/color]

        In most but not all browsers - see FAQ, 4.15.
        [color=blue]
        >"Evertjan." <exjxw.hannivoo rt@interxnl.net > wrote in message
        >news:Xns95A3AD AA3F1E7eejj99@1 94.109.133.29.. .[/color]
        [color=blue][color=green]
        >> document.getEle mentById("div1" ).innerHTML="He llo"[/color][/color]

        --
        © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
        Web <URL:http://www.merlyn.demo n.co.uk/> - FAQish topics, acronyms, & links.
        Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
        Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)

        Comment

        • Evertjan.

          #5
          Re: Can JavaScript place HTML code into Div...?

          Dr John Stockton wrote on 16 nov 2004 in comp.lang.javas cript:[color=blue][color=green][color=darkred]
          >>> document.getEle mentById("div1" ).innerHTML="He llo"[/color]
          >>Thanks, it does exactly what I needed,[/color]
          > In most but not all browsers - see FAQ, 4.15.[/color]

          While this is true, John,
          the OP clearly shows a to be a newbee,
          and a complete solution would scare the OP off,
          which is worse IMHO, than the incompliance.

          btw: Having javascript switched off could be
          a far more probable problem,
          than having a innerHTML incompliant browser.

          --
          Evertjan.
          The Netherlands.
          (Please change the x'es to dots in my emailaddress,
          but let us keep the discussions in the newsgroup)

          Comment

          • Dr John Stockton

            #6
            Re: Can JavaScript place HTML code into Div...?

            JRS: In article <Xns95A45FEA9DB 0Beejj99@194.10 9.133.29>, dated Wed, 17
            Nov 2004 08:25:39, seen in news:comp.lang. javascript, Evertjan.
            <exjxw.hannivoo rt@interxnl.net > posted :[color=blue]
            >Dr John Stockton wrote on 16 nov 2004 in comp.lang.javas cript:[color=green][color=darkred]
            >>>> document.getEle mentById("div1" ).innerHTML="He llo"
            >>>Thanks, it does exactly what I needed,[/color]
            >> In most but not all browsers - see FAQ, 4.15.[/color]
            >
            >While this is true, John,
            >the OP clearly shows a to be a newbee,
            >and a complete solution would scare the OP off,
            >which is worse IMHO, than the incompliance.
            >
            >btw: Having javascript switched off could be
            >a far more probable problem,
            >than having a innerHTML incompliant browser.[/color]

            It is not for us to decide what the reader is allowed to know; it is for
            the reader to decide what he needs to support, knowing that the solution
            you gave is not universal. A reference to the FAQ achieves that
            warning.

            So does "Older browsers may not know getElementById; it can be provided
            if needed by
            if (document.all && !document.getEl ementById) {
            document.getEle mentById = function(id) {
            return document.all[id] } } // "

            // (which seems OK to me, and works in IE4.)

            Moreover, since he *is* asking about something which the FAQ answers,
            then he should in any case be referred to the FAQ; he may very well find
            there answers to future questions.

            --
            © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
            <URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
            <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
            <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

            Comment

            • Evertjan.

              #7
              Re: Can JavaScript place HTML code into Div...?

              Dr John Stockton wrote on 17 nov 2004 in comp.lang.javas cript:
              [color=blue]
              > Moreover, since he *is* asking about something which the FAQ answers,
              > then he should in any case be referred to the FAQ;[/color]

              "should"?

              I don't think so, John.

              A straight answer is not against netiquette, even if there is a NG-FAQ.

              I would agree on "could".
              [color=blue]
              > he may very well find there answers to future questions.[/color]

              Undoubtedly, he may.

              --
              Evertjan.
              The Netherlands.
              (Please change the x'es to dots in my emailaddress,
              but let us keep the discussions in the newsgroup)

              Comment

              Working...