By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,480 Members | 1,214 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,480 IT Pros & Developers. It's quick & easy.

Disable button by clearing checkbox

P: 64
I have a form where a user can select items via a check box. Once an item is checked it will enable a button to appear so that the user can add the items to a shopping cart. I have the first part of the JavaScript working which allows the button to appear if the checkbox is true.

The problem that I am having is when I decide to deselect the last remaining box. It does not disable the add button. The first part works, the second part does nothing. Also, there are no JavaScript errors.


Expand|Select|Wrap|Line Numbers
  2. function boxChecked(field)
  3. {
  4.   var 1 = 0;
  5.   if(field[i].checked = true)
  6.   {
  7.    var x=document.getElementById("mybutton")
  8.    x.disable=false;
  9.   }
  10.   else
  11.   if(field[i].checked = false)
  12.   {
  13.   var x=document.getElementById("mybutton")
  14.   x.disable=true;
Jul 12 '12 #1
Share this Question
Share on Google+
4 Replies

Expert Mod 5K+
P: 8,639
thatís because = is the assignment operator.

tip: reverse variable and value.
Expand|Select|Wrap|Line Numbers
  1. if (box.checked = false) // no error
  3. if (false = box.checked) // error: cannot assign to a constant
Jul 12 '12 #2

P: 64
Hello Dormilich,

Although this does not produce an error, it does not work. The same remains even with your recommendation. The first part works, but the 2nd part does nothing. Thanks for replying anyhow.

Jul 13 '12 #3

Expert Mod 5K+
P: 8,639
er, my code was not meant as a working demonstration. it is an example to demonstrate the problem.

you are just mistaking the assignment operator for the comparison operator. the given code shows a possibility to write code in a way that you can’t mistake one for the other.
Jul 13 '12 #4

P: 64

Jul 13 '12 #5

Post your reply

Sign in to post your reply or Sign up for a free account.