javascript

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

    #1

    javascript

    hello, how can i write a text on web page with javascript:

    like in PHP <? echo "bla_bla_bl a"?>


    <script language="javas cript" type="text/javascript">
    print 'bla_bla_bla';
    </script>


  • Ulrik Skovenborg

    #2
    Re: javascript

    uso wrote:[color=blue]
    > hello, how can i write a text on web page with javascript:[/color]

    In javascript you use document.write( ):
    <script type="text/javascript">
    document.write( "blablalbal ");
    </script>

    Comment

    • uso

      #3
      Re: javascript

      [color=blue]
      > uso wrote:[color=green]
      >> hello, how can i write a text on web page with javascript:[/color]
      >
      > In javascript you use document.write( ):
      > <script type="text/javascript">
      > document.write( "blablalbal ");
      > </script>[/color]

      thx. but it writes the blablabla in new , how to write it in the sam web
      page


      Comment

      • Ulrik Skovenborg

        #4
        Re: javascript

        uso wrote:[color=blue][color=green]
        >>uso wrote:
        >>In javascript you use document.write( ):
        >><script type="text/javascript">
        >> document.write( "blablalbal ");
        >></script>[/color]
        >
        >
        > thx. but it writes the blablabla in new , how to write it in the sam web
        > page
        >[/color]

        Yes the problem with document.write is that it only works as you may
        expect before the whole page is loaded (and the DOM Tree is still to be
        completed). That's why document.write and print (in PHP) works pretty
        much the same way and are only used when generating the page.

        To add text to the page after the page is loaded is another problem.
        There are several ways to accomplish this but one of the easist one is
        to use the innerHTML-property that every HTML-element has:

        document.getEle mentById("eleme ntID").innerHTM L = "TExt";
        or
        document.body.i nnerHTML += "text"; // adds the text directly to the
        body-element

        You shouldn't try this method before the whole page is loaded though.
        The element you try to add the text to might not be comlete yet.

        Comment

        • Dr John Stockton

          #5
          Re: javascript

          JRS: In article <d7cgsi$3us$1@m agcargo.vodatel .hr>, dated Sun, 29 May
          2005 15:43:16, seen in news:comp.lang. javascript, uso <bobo@hotmail.c om>
          posted :[color=blue]
          >[color=green]
          >> uso wrote:[color=darkred]
          >>> hello, how can i write a text on web page with javascript:[/color]
          >>
          >> In javascript you use document.write( ):
          >> <script type="text/javascript">
          >> document.write( "blablalbal ");
          >> </script>[/color]
          >
          >thx. but it writes the blablabla in new , how to write it in the sam web
          >page[/color]

          Read FAQ 4.15 for that.

          Please use a properly informative Subject line.

          For proper quoting when using Google for News :-
          Keith Thompson wrote in comp.lang.c, message ID
          <lnwtuhfy7d.fsf @nuthaus.mib.or g> :-
          If you want to post a followup via groups.google.c om, don't use
          the "Reply" link at the bottom of the article. Click on "show
          options" at the top of the article, then click on the "Reply" at
          the bottom of the article headers.

          Since that is what the experts in this newsgroup prefer to read, it will
          be to your advantage to comply.

          --
          © 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

          • RobG

            #6
            Re: javascript

            Ulrik Skovenborg wrote:
            [...][color=blue]
            >
            > document.getEle mentById("eleme ntID").innerHTM L = "TExt";
            > or
            > document.body.i nnerHTML += "text"; // adds the text directly to the
            > body-element
            >
            > You shouldn't try this method before the whole page is loaded though.
            > The element you try to add the text to might not be comlete yet.[/color]

            Replacing the body.innerHTML will have pretty much the same effect as
            using document.write( ) - the current content will be obliterated.

            Much better to use DOM methods to create the required elements and
            append them to appropriate nodes. innerHTML, though widely supported,
            is not a W3C standard and is most useful for replacing the content of
            an element with some other (reasonably simple) content.

            To the OP: research 'createElement' .

            <URL:http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-2141741547>

            <URL:http://www.mozilla.org/docs/dom/domref/dom_doc_ref.htm l#998664>

            <URL:http://msdn.microsoft. com/library/default.asp?url =/library/en-us/dndude/html/dude100499.asp>

            --
            Rob

            Comment

            Working...