Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Sep 2002
    Posts
    218
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question getting a link to change a peice of text...

    Hey there,

    I have a pretty simple idea, i just want a link to change a peice of text to something else. eg if the text says 'mouse' and i click a link 'cheese' i want the text to change to 'cheese' i know i can pass what i want the text to become to a javascript function but im not sure how to change the text.

    Cheers

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    <html>
    <head>
    <script type="text/javascript">
    function changeText(txt){
    document.getElementById("mydiv").innerHTML=txt;
    return false;
    }
    </script>
    </head>
    <body>
    <a href="#" onclick="return changeText('cheese')">cheese</a>
    <a href="#" onclick="return changeText('<b>text</b>')">bold text</a>
    <div id="mydiv">mouse</div>
    </body>
    </html>

  • #3
    Regular Coder
    Join Date
    Sep 2002
    Posts
    218
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks for that, works nicely.

    this has got me thinking, is there a way for javascript to get the text that its gonna change to from a .txt file?

    coz you could use this as a replacement for small iframes if javascript could do that....

  • #4
    Regular Coder
    Join Date
    Nov 2002
    Posts
    672
    Thanks
    1
    Thanked 1 Time in 1 Post
    Javascript alone can't red an external file. But you could store a variable (or array of variables) in an external script file for easy mainenance. This would probably be the best solution if you are using this script on many pages.

    Oh yea, I document.write() my email on many pages all by calling a single script file. darn Tripod spyders.

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Posts
    338
    Thanks
    0
    Thanked 0 Times in 0 Posts
    CHeck this thread out for more information.


  •  

    Posting Permissions

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