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 2 of 2

Thread: Writing text

  1. #1
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Writing text

    My Problem:
    Right now, what I am trying to make happen is whenever a link is pressed, I want function getText(a) to write new text
    into the id element “cont” via showPic(), how do I do that?
    I’m stumped...

    //variables
    var jan = "The traditional birthstone for January is Garnet”;
    var feb = "The traditional birthstone for February is Amethyst”;


    //Javascript
    function getText (a) {
    document.write(a)

    }

    function showPic (whichpic, content) {
    if (document.getElementById) {
    document.getElementById('placeholder').src = whichpic.href;
    if (whichpic.title) {
    document.getElementById('cont').childNodes[0].nodeValue =
    <!--How do I fit getText(content) into here?-->
    }
    return false;
    } else {
    return true;
    }
    }

    //Buttons
    <a onclick="return showPic(this, jan);return false;"
    href="../images/bananas.jpg" title="January - Garnet">January</a>
    <a onclick="return showPic(this, feb);return false;"
    href="../images/condiments.jpg" title="February - Amethyst">February</a>


    //ID “cont”
    <td valign="top" id="cont">hello</td>

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,505
    Thanks
    3
    Thanked 501 Times in 488 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    
    <head>
      <title></title>
    </head>
    
    <body>
    My Problem:
    Right now, what I am trying to make happen is whenever a link is pressed, I want function getText(a) to write new text
    into the id element “cont” via showPic(), how do I do that?
    I’m stumped...
    <script language="JavaScript" type="text/javascript">
    <!--
    
    //variables
    var jan = "The traditional birthstone for January is Garnet";
    var feb = "The traditional birthstone for February is Amethyst";
    
    
    //Javascript
    function getText (a) {
    document.write(a)
    
    }
    
    function showPic (whichpic, content) {
     if (document.getElementById) {
    //document.getElementById('placeholder').src = whichpic.href;
    // if (whichpic.title) {
      document.getElementById('cont').childNodes[0].nodeValue = content;
    //or
    //  document.getElementById('cont').childNodes[0].data = content;
    
    
    // }
     return false;
     }
     else {
      return true;
     }
    }
    
    //-->
    </script>
    //Buttons
    <a onclick="return showPic(this, jan);return false;"
    href="../images/bananas.jpg" title="January - Garnet">January</a>
    <a onclick="return showPic(this, feb);return false;"
    href="../images/condiments.jpg" title="February - Amethyst">February</a>
    
    
    <p valign="top" id="cont" >hello</p>
    jmh722 is offline   	Reply With Quote
    <script language="JavaScript" type="text/javascript">
    <!--
     showPic ('',feb)
    //-->
    </script>
    </body>
    
    </html>


  •  

    Posting Permissions

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