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])})
http://jsfiddle.net/L33JK/16/
EDIT: improved with help from @Daniel Lisik - https://codegolf.stackexchange.com/a/26805/16278
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
.
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)
F←{B.Active←X∨2≠+/X←B.State}
Newer bits of APL have long keywords. I still beat HTML though.
Explanation:
'R'⎕WC'Form' 'Select any two',2/⊂S←2/20
: create a formR
, with title Select any two and size and position20 20
. Also stores20 20
inS
.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 withinR
with the first letter of the name,⍵(⍺1)S'Check'
: with the right argument as the title,(left arg, 1)
as position, reusingS
as the size andCheck
as style,('Event' 'Select' 'F')
, which calls the functionF
when clicked.
B←R.(F C G)
: useB
as an abbreviation for the three checkboxes we createdF←{
...}
: define the callback function as:X←B.State
: get the state for each checkbox and store them inX
,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 activeB.Active←
: enable or disable the checkboxes
Result: