Combining two onclick commands

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sfrasier
    New Member
    • Apr 2010
    • 1

    Combining two onclick commands

    i am trying to combine the 2 following onclick commands. I have tried every combination i can think of but can only get the first comand to execute.

    the commands are for
    <script>
    var count1
    </script>

    the two onclick commands are:
    1. onclick="count1 =count+1"
    2.onclick="if(c ount1%2==1)this .style.backgrou nd='red' ;else this.style.back ground='white'; "
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    Hi sfrasier,
    you can achieve that in any no. of ways

    method1:

    Code:
    onclick="count1=count+1; if(count1%2==1){this.style.background='red';}else{this.style.background='white';}"
    method2:

    you can have a function and pass the object to that function

    Code:
    onclick="doThis(this)";
    
    function doThis(ths){
       count1=count+1;
      if(count1%2==1)
         ths.style.background='red';
      else
         ths.style.background='white'; 
    }
    Thanks and Regards
    Ramanan Kalirajan

    Comment

    Working...