www.webdeveloper.com
Results 1 to 2 of 2

Thread: Onclick

  1. #1
    Join Date
    Mar 2012
    Posts
    1

    Onclick

    Hi,

    I have this code below that I need some help with. What I want to achieve is that when I click the buttons the text changes back and forth between false and true. Tha last field shows the result: false + false = false or false + true = false or true + true = true. Thanks.


    <html>
    <head>

    <script type="text/javascript">

    var alight = false;
    var blight = false;

    function update ()
    {
    document.getElementById("c").value=alight && blight
    }

    </script>
    </head>

    <body>

    <p>
    <input id="a">
    <input type="button" value="x" onclick="document.getElementById('a').value=alight; update();">
    </p>
    <p>
    <input id="b">
    <input type="button" value="x" onclick="document.getElementById('b').value=blight; update();">
    </p>
    <p>


    <input id="c">
    </p>
    </body>
    </html>

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,330

    Lightbulb

    You need to change something, not just display its' current status.
    Code:
    <html>
    <head>
    
    <script type="text/javascript">
    
    var alight = false;
    var blight = false;
    
    function update () {
    document.getElementById("c").value=alight && blight
    }
    
    </script>
    </head>
    
    <body>
    
    <p>
    <input id="a">
    <input type="button" value="x" onclick="alight=!alight;document.getElementById('a').value=alight; update();">
    </p>
    <p>
    <input id="b">
    <input type="button" value="x" onclick="blight=!blight;document.getElementById('b').value=blight; update();">
    </p>
    <p>
    
    
    <input id="c">
    </p>
    </body>
    </html>
    BTW: You should enclose your script between [ code] and [ /code] tags (without the spaces)
    to make it easier to analyze your post.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles