It is allowing me to select more buttons than I should do

Please follow these steps in the jsfiddle

  1. Click on open grid link and select option “3”, buttons A,B and C would appear

  2. Enter in number 2 in the number of Answers textbox. Then select buttons A and C

  3. Now click on the open grid again and select option 6.

  4. Now the number of Answers textbox is empty so type in 2 again in the text-box. So only 2 answers should be selected which is A and C. So if you click on another button the alert message should appear stating you are beyond limit, deselect another button. But this does not happen. Instead the user can select another 2 buttons and then the alert message would appear if another button is selected. This means that 4 buttons are selected which is incorrect, it should still be 2.

So does anyone have an idea why it is doing this?

Thanks

Code is in jsfiddle, click here