Fast, Cheap, and Good - Choose any Two

JavaScript - 184 169 (with jQuery)

b="input",a="<input type=checkbox>",c=":checked";$("body").html("SELECT ANY TWO"+a+"FAST"+a+"GOOD"+a+"CHEAP").click(function(){$(b).not(c).attr("disabled",!!$(b+c)[1])})

EDIT: improved with help from @Daniel Lisik -

Javascript (ES5) with jQuery - 143 (Demo)

I modified Matt's solution and golfed it as far down as I think it can go:

$("*").html(["SELECT ANY TWO","FAST","GOOD","CHEAP"].join("<input type=checkbox onclick=(a=$('input:not(:checked)')).prop('disabled',!a[1])>"))

Javascript (ES5) without jQuery - 185 175 (Demo)

Using jQuery is kind of cheating, so here's a solution without it:

(d=document).write(["SELECT ANY TWO","FAST","GOOD","CHEAP"].join("<input type=checkbox onclick='for(b in a=d.querySelectorAll(\"input:not(:checked)\"))a[b].disabled=!a[1]'>"))

If we're allowed to prevent the user from checking the 3rd box instead of actually disabling the field, we can make it even shorter:

With jQuery - 126 123 (Demo)

$("*").html(["SELECT ANY TWO","FAST","GOOD","CHEAP"].join("<input type=checkbox onclick=this.checked*=!$(':checked')[2]>"))

Without jQuery - 150 147 (Demo)

(d=document).write(["SELECT ANY TWO","FAST","GOOD","CHEAP"].join("<input type=checkbox onclick=this.checked*=!d.querySelectorAll(':checked')[2]>"))

Dyalog APL (on Windows) (169)

This is a static function, to test it if you don't know APL, type )ed C and paste this in the edit window, then run C.

'R'⎕WC'Form' 'Select any two',2/⊂S←2/20
1 21 41{('R.',⊃⍵)⎕WC'Button'⍵(⍺1)S'Check'('Event' 'Select' 'F')}¨'Fast' 'Cheap' 'Good'
B←R.(F C G)

Newer bits of APL have long keywords. I still beat HTML though.


  • 'R'⎕WC'Form' 'Select any two',2/⊂S←2/20: create a form R, with title Select any two and size and position 20 20. Also stores 20 20 in S.
  • 1 21 41{...}¨'Fast' 'Cheap' 'Good': for each of these pairs of data (name and y-coordinate, which are the only variables that differ between the checkboxes:
    • ('R.',⊃⍵)⎕WC'Button': create a button within R with the first letter of the name,
    • ⍵(⍺1)S'Check': with the right argument as the title, (left arg, 1) as position, reusing S as the size and Check as style,
    • ('Event' 'Select' 'F'), which calls the function F when clicked.
  • B←R.(F C G): use B as an abbreviation for the three checkboxes we created
  • F←{...}: define the callback function as:
    • X←B.State: get the state for each checkbox and store them in X,
    • X∨2≠+/X: sum X, if this is not equal to two all checkboxes must be active, if it is equal to two only checked checkboxes must be active
    • B.Active←: enable or disable the checkboxes