www.webdeveloper.com
Results 1 to 3 of 3

Thread: This code for buttons isn't working...

  1. #1
    Join Date
    Oct 2010
    Location
    On a BOAT!
    Posts
    7

    This code for buttons isn't working...

    Why doesn't this code work????

    Code:
    <head>
    <script language="javascript" type="text/javascript">
    var rD = 2;
    var gN = 2;
    var bL = 2;
    var iD_is;
    rD is the # of red buttons "on",
    gN is the # of green buttons "on",
    bL is the # of blue buttons "on", &
    iD_is is the id of the img to change.
    Code:
    </script>
    <script language="javascript" type="text/javascript">
    function red_down()
    {if (rD != 0);{rD-=1};
    if (rD = 0);{iD_is = 'r1'};
    if (rD = 1);{iD_is = 'r2'};
    {document.getElementById(iD_is).src = 'http://bit.ly/red_xed'};}
    </script>
    <script language="javascript" type="text/javascript">
    function green_down()
    {if (gN != 0);{bL-=1};
    if (gN = 0);{iD_is = 'g1'};
    if (gN = 1);{iD_is = 'g2'};
    {document.getElementById(iD_is).src = 'http://bit.ly/green_xed'};}
    </script>
    <script language="javascript" type="text/javascript">
    function blue_down()
    {if (bL != 0);{bL-=1};
    if (bL = 0);{iD_is = 'b1'};
    if (bL = 1);{iD_is = 'b2'};
    {document.getElementById(iD_is).src = 'http://bit.ly/blue-xed'};}
    </script>
    <script language="javascript" type="text/javascript">
    function red_up()
    {if (rD != 2);{rD+=1};
    if (rD = 2);{iD_is = 'r2'};
    if (rD = 1);{iD_is = 'r1'};
    {document.getElementById(iD_is).src = 'http://bit.ly/red_button'};}
    </script>
    <script language="javascript" type="text/javascript">
    function green_up()
    {if (gN != 2);{gN+=1};
    if (gN = 2);{iD_is = 'g2'};
    if (gN = 1);{iD_is = 'g1'};
    {document.getElementById(iD_is).src = 'http://bit.ly/green_button'};}
    </script>
    <script language="javascript" type="text/javascript">
    function blue_up()
    {if (bL != 2);{bL+=1};
    if (bL = 2);{iD_is = 'b2'};
    if (bL = 1);{iD_is = 'b1'};
    {document.getElementById(iD_is).src = 'http://bit.ly/blue-button'};}
    </script>
    </head>
    <body>
    <table>
       <tr>
          <td><button onclick="red_down()">-</button></td>
          <td><button onclick="green_down()">-</button></td>
          <td><button onclick="blue_down()">-</button></td>
       </tr>
       <tr>
          <td><img id="r1" src="http://bit.ly/red_button"></td>
          <td><img id="g1" src="http://bit.ly/green_button"></td>
          <td><img id="b1" src="http://bit.ly/blue-button"></td>
       </tr>
       <tr>
          <td><img id="r2" src="http://bit.ly/red_button"></td>
          <td><img id="g2" src="http://bit.ly/green_button"></td>
          <td><img id="b2" src="http://bit.ly/blue-button"></td>
       </tr>
       <tr>
          <td><button onclick="red_up()">+</button></td>
          <td><button onclick="green_up()">+</button></td>
          <td><button onclick="blue_up()">+</button></td>
       </tr>
    </table>
    </body>
    It is supposed be just 2 different lines of changing buttons. I was planning to use the "+" and "-" buttons to add/subtract button lights from a column. Unless I did something wrong, I think it should work, but it doesn't... Why?
    Last edited by wethammy123; 03-21-2011 at 09:17 PM.

  2. #2
    Join Date
    Sep 2008
    Location
    Jackson MS
    Posts
    373
    You use == in an if statement and there is no ; after an if statement before what you want to do if the statement is true.
    Code:
    if (rD == 2) {iD_is = 'r2';}

  3. #3
    Join Date
    Oct 2010
    Location
    On a BOAT!
    Posts
    7
    Thanks. I wasn't sure about that. I've done things like this before, but usually have to start from scratch when I want to do something new.

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