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
  1. #1
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    innerHTML and ChangeText of multiple values

    I need for the text to change on my page. I want it to change to 'value a' when 'button a' is pressed, and 'value b' when 'button b' is pressed. All the tutorials online only solve for a single value change with a single button. I am new to java, so please advise. The example below has the second button I want, it just doesn't change the value. Only the first button does. Thanks for your time.

    P.S. I am new to java, so I'm not sure if this actually qualifies as an AJAX question, or just a general HTML question.


    <html>
    <head>
    <script language="JavaScript" type = "text/javascript">
    function ChangeText()
    {
    var curtextval = document.getElementById("ptext");
    curtextval.innerHTML = "Text is now A"
    }
    </script>
    </head>
    <body>
    <form>
    <p id="ptext">This is the original text</p>
    <input type="button" value="Change Text to A" onClick="ChangeText()"></p>
    <input type="button" value="Change Text to B" onClick="ChangeText()"></p>

    </form>
    </body>
    </html>

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <script type = "text/javascript">
    function ChangeText(str)
    {
    var curtextval = document.getElementById("ptext");
    curtextval.innerHTML = "Text is now "+str;
    }
    </script>
    </head>
    <body>
    <form>
    <p id="ptext">This is the original text</p>
    <input type="button" value="Change Text to A" onClick="ChangeText('A')"></p>
    <input type="button" value="Change Text to B" onClick="ChangeText('B')"></p>
    
    </form>
    </body>
    </html>
    P.S. I am new to java, so I'm not sure if this actually qualifies as an AJAX question, or just a general HTML question.
    Java and javascript are not the same. And surely this is not an AJAX question.
    Last edited by abduraooft; 01-12-2009 at 07:29 AM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

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