• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

disable button when no checkboxes

 
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a set of check boxes and
I wanted to know if there was anyway i could implement following behavior:
if all checkboxes are unchecked then disable button else enable button
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You sure can.

First loop through all the checkboxes in the form to find if anything is checked. If nothing is checked you can change the flip the 'disabled' flag on the button.

It will be more like :


Invoke the above code using onLoad() on the page

Also check
http://www.quirksmode.org/js/disabled.html
http://www.faqts.com/knowledge_base/view.phtml/aid/1747
 
Pranav Sharma
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry I should have mentioned, i know how to disable the check box but unable to perform the test everytime a checkbox is checked/unchecked.

So the onload will not work. How would i do it 'dynamically', onchange does not seem to work i guess the value does not change....
 
author & internet detective
Posts: 40549
825
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mannu,
You could use onBlur to see when the checkbox was active. This wouldn't tell you for sure if something changed. But it will tell you something might have changed and then you can run your function to see if no checkboxes are currently selected.
 
Sheriff
Posts: 67537
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd use the onclick handler.
 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can use setInterval and check all the checkboxes every half-second or even smaller interval
 
Pranav Sharma
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
all, thanks for the replies.

onclick works. I thought maybe checking intervals was probably overkill because i could have upto 100 check boxes and users could bypass it.

However it would be great to know why onchange did not work...thanks anyways
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic