SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2002
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile How to change text with a link without a form?

    I need to dynamically change text based on links you click. I know how to do this easily using a text area, but I'm not sure how to do it with plain text. Any suggestions?

    Example:

    This word will change when you click a link: WORD

    HELLO - GOODBYE - WELCOME - (custom word)

    (now say you click "HELLO", "WORD" would change to "HELLO". Entering a custom word would put the custom word there.

    Is there any way to do this dynamically? I've looked everywhere for answers.

    thanks!!

    myke

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HTML Code:
    <p>This word will change when you click a link: <b id="word">WORD</b></p>
    
    <p><a href="#" id="hello">HELLO</a> - ...</p>
    Code:
    function setWord(newWord)
    {
        var e = document.getElementById("word");
        e.firstChild.nodeValue = newWord;
    }
    
    document.getElementById("hello").onclick = function() {setWord("HELLO");}
    ...
    Birnam wood is come to Dunsinane


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •