0

i want to detect the the checkbox is checked or not and i successfully does this now if user uncheck it then how can i detech this? my code is this

window.updated = function() {

    var x = document.getElementById("new").checked;
    if(x=true)
    {
        alert("true");
    }
    else
    {
         var tw1 = document.getElementById('tw1');

            tw1.value = '';
            document.getElementById('tw1').readOnly=false;
            //2nd

          tw2 = document.getElementById('tw2');    
            tw2.value = '';
            document.getElementById('tw2').readOnly=false;
            //3rd
         tw3 = document.getElementById('tw3');    
            tw3.value = '';
            document.getElementById('tw3').readOnly=false;
            //4th
         tw4 = document.getElementById('tw4');    
            tw4.value = '';
            document.getElementById('tw4').readOnly=false;
            //5th
         tw5 = document.getElementById('tw5');    
            tw6.value = '';
            document.getElementById('tw5').readOnly=false;
            //6th
         tw6 = document.getElementById('tw6');    
            tw6.value = '';
            document.getElementById('tw6').readOnly=false;
            //7th

      tw7 = document.getElementById('tw7');    
            tw7.value = '';
            document.getElementById('tw7').readOnly=false;
    }
             var ne1 = document.getElementById('ne1'),
          tw1 = document.getElementById('tw1');    
            tw1.value = ne1.value;
            document.getElementById('tw1').readOnly=true
            //2nd
              var ne2 = document.getElementById('ne2'),
          tw2 = document.getElementById('tw2');    
            tw2.value = ne2.value;
            document.getElementById('tw2').readOnly=true
            //3rd
              var ne3 = document.getElementById('ne3'),
          tw3 = document.getElementById('tw3');    
            tw3.value = ne3.value;
            document.getElementById('tw3').readOnly=true
            //4th
              var ne4 = document.getElementById('ne4'),
          tw4 = document.getElementById('tw4');    
            tw4.value = ne4.value;
            document.getElementById('tw4').readOnly=true
            //5th
              var ne5 = document.getElementById('ne5'),
          tw5 = document.getElementById('tw5');    
            tw5.value = ne5.value;
            document.getElementById('tw5').readOnly=true
            //6th
              var ne6 = document.getElementById('ne6'),
          tw6 = document.getElementById('tw6');    
            tw6.value = ne6.value;
            document.getElementById('tw6').readOnly=true
            //7th
              var ne7 = document.getElementById('ne7'),
          tw7 = document.getElementById('tw7');    
            tw7.value = ne7.value;
            document.getElementById('tw7').readOnly=true
    }

If you check a checkbox it puts the data from the billing info inputs into the shipping info inputs.

However, I always get true after unchecking the checkbox as well.

1 Answer 1

3

your not comparing here your assigning (x=true). that should just be if (x)

this x = true assigns the value of true to x and then evaluates it in the if statement. Thats why it's always true
this x == true returns true if the operands are equal.
this x === true returns true if the operands are equal and of the same type

2
  • 2
    @user3081499: You should accept this answer if it works for you, by clicking the check mark on the left side of the answer.
    – Jeff B
    Commented Dec 19, 2013 at 23:21
  • i did it. now .you have to wait 15 min after anyone answerd you. Commented Dec 19, 2013 at 23:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.