Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Javascript text

Javascript text

Scheduled Pinned Locked Moved Web Development
javascriptquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    totig
    wrote on last edited by
    #1

    Sorry about the useless subject line. Say I have two buttons. Is there anyway I can use javascript, to change text displayed on the screen, depending on which button I use? If so, please let me know what it is.

    I 1 Reply Last reply
    0
    • T totig

      Sorry about the useless subject line. Say I have two buttons. Is there anyway I can use javascript, to change text displayed on the screen, depending on which button I use? If so, please let me know what it is.

      I Offline
      I Offline
      Ian Darling
      wrote on last edited by
      #2

      Use a span or something, and set the innerHTML:

      <span id="Thing">Text</span>
      
      <script>
      function SetText(id, text)
      {
      document.all[id].innerHTML = text
      }
      </script>
      <input type=button onclick="SetText('Thing', 'Hello World');>
      

      Untested, but is more or less what you want to get started. -- Ian Darling If I was any more loopy, I'd be infinite.

      B 1 Reply Last reply
      0
      • I Ian Darling

        Use a span or something, and set the innerHTML:

        <span id="Thing">Text</span>
        
        <script>
        function SetText(id, text)
        {
        document.all[id].innerHTML = text
        }
        </script>
        <input type=button onclick="SetText('Thing', 'Hello World');>
        

        Untested, but is more or less what you want to get started. -- Ian Darling If I was any more loopy, I'd be infinite.

        B Offline
        B Offline
        Bjoern Graf
        wrote on last edited by
        #3

        But don't use an IE only DOM 0 thingy (hint: document.all) if it's possible to stay compatible with most (actually all) browsers by using document.getElementById(id).innerHTML = text;.

        D 1 Reply Last reply
        0
        • B Bjoern Graf

          But don't use an IE only DOM 0 thingy (hint: document.all) if it's possible to stay compatible with most (actually all) browsers by using document.getElementById(id).innerHTML = text;.

          D Offline
          D Offline
          DFU23
          wrote on last edited by
          #4

          Good point about standards ... But innerHTML is not actually a W3C standard ... even though it is widely supported among most browsers, weird[^].

          Wally Atkins
          Newport News, VA, USA

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups