Change text on a page

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

    Change text on a page

    Using JavaScript, can I tag a block of text and then change the text
    appearing in that block?

    I'm doing a type of calculator and I'd like to display the resulting
    number in a <td> (or div or whatever works) on the page. I'd like to
    avoid using a text form field for the output.

    Thanks.

  • VK

    #2
    Re: Change text on a page

    > I'm doing a type of calculator and I'd like to display the resulting[color=blue]
    > number in a <td> (or div or whatever works) on the page. I'd like to
    > avoid using a text form field for the output.[/color]

    Works nearly everything. "Quick-n-durty" way is

    ....
    <td id="Output">Ol d text</td>
    ....

    var myText = "New text";
    var myHTML = "<b>New text</b>";
    var out = document.getEle mentById("Outpu t");
    out.innerText = myText;
    /* or
    out.innerHTML = myHTML; */

    The same with div and any other HTML tag. Just give them an ID.


    Comment

    • Stuart Palmer

      #3
      Re: Change text on a page

      don't think innerHTML works with older netscapes though.
      Stu

      "VK" <schools_ring@y ahoo.com> wrote in message
      news:3fd3c147$0 $10074$9b622d9e @news.freenet.d e...[color=blue][color=green]
      > > I'm doing a type of calculator and I'd like to display the resulting
      > > number in a <td> (or div or whatever works) on the page. I'd like to
      > > avoid using a text form field for the output.[/color]
      >
      > Works nearly everything. "Quick-n-durty" way is
      >
      > ...
      > <td id="Output">Ol d text</td>
      > ...
      >
      > var myText = "New text";
      > var myHTML = "<b>New text</b>";
      > var out = document.getEle mentById("Outpu t");
      > out.innerText = myText;
      > /* or
      > out.innerHTML = myHTML; */
      >
      > The same with div and any other HTML tag. Just give them an ID.
      >
      >[/color]


      Comment

      • Fabian

        #4
        Re: Change text on a page

        Stuart Palmer hu kiteb:
        [color=blue]
        > don't think innerHTML works with older netscapes though.
        > Stu[/color]

        How many hands do you need to count those people still using such
        netscapes?


        --
        --
        Fabian
        Visit my website often and for long periods!
        Kenali metode Martingale untuk permainan slot online bersama AGAM69. Simak panduan lengkap mengenai strategi taruhan, manajemen saldo, dan cara bermain dengan lebih terencana.


        Comment

        • Thomas 'PointedEars' Lahn

          #5
          Re: Change text on a page

          Jim Mc wrote:
          [color=blue]
          > Using JavaScript, can I tag a block of text and then change the text
          > appearing in that block?[/color]

          Yes, if the DOM of the UA supports that.
          [color=blue]
          > I'm doing a type of calculator and I'd like to display the resulting
          > number in a <td> (or div or whatever works) on the page.[/color]

          Use DOM methods to get a reference to the `td' element and use DOM
          properties to change its content. You find plenty of postings in
          the newsgroup about it, please always search/read before you post.
          [color=blue]
          > I'd like to avoid using a text form field for the output.[/color]

          Why, using forms that is the most compatible way to accomplish that.


          PointedEars

          Comment

          • Stephen Poley

            #6
            Re: Change text on a page

            On Mon, 8 Dec 2003 17:34:07 +0900, "Fabian" <lajzar@hotmail .com> wrote:
            [color=blue]
            >Stuart Palmer hu kiteb:
            >[color=green]
            >> don't think innerHTML works with older netscapes though.
            >> Stu[/color]
            >
            >How many hands do you need to count those people still using such
            >netscapes?[/color]

            I still have about 3% Netscape 4 visitors to my site. Not worth putting
            a lot of effort into making a beautiful page for them, but worth making
            sure it degrades gracefully.

            --
            Stephen Poley

            Comment

            • Dr John Stockton

              #7
              Re: Change text on a page

              JRS: In article <bnc7tv0k0lkl9r ebpg2htg1ou21jt cj5qr@4ax.com>, seen in
              news:comp.lang. javascript, Jim Mc <jim.mc@zolx.co m> posted at Sun, 7 Dec
              2003 16:10:52 :-[color=blue]
              >Using JavaScript, can I tag a block of text and then change the text
              >appearing in that block?
              >
              >I'm doing a type of calculator and I'd like to display the resulting
              >number in a <td> (or div or whatever works) on the page. I'd like to
              >avoid using a text form field for the output.[/color]

              Before posting (or answering), one should read the newsgroup FAQ. That
              one is answered in Sec 4.15, in a manner compatible with two main
              classes of browser.

              =

              Draft <URL:http://www.merlyn.demo n.co.uk/hols.htm> (27 kB) needs
              checking in different browsers. It uses FAQ 4.15 to write into a Div.

              Primarily, does the bottom button give a Table, and does changing the
              top entry in the right hand column change the other entries accordingly?

              Secondarily (BI & NA only), do the BI / NA Tables show correct results?

              Thirdly, do the words make sense?

              Fourthly, does anyone know about holidays *controlled* by the EU or at
              EU HQ?

              --
              © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
              <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
              <URL:http://www.merlyn.demo n.co.uk/js-index.htm> JS maths, dates, sources.
              <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.

              Comment

              Working...