While it can be done with javascript to
enhance user experience, you, first, need to design a usable form without relying on javascript.
Considering your post in HTML section, the checkbox seems to be a superfluous element. Why not default your quantity textboxes to 0 so that if a user wants an item he/she changes the text in that box to a different value. This scenario does not require client side scripting to be operational and reduces the amount of "clicks" user has to make to get the result.
As far as that code above goes it is way too inefficient. Here is how you implement this approach (points of emphasis in red)
Code:
<script type="text/javasript">
function buyThis(checkbox)
{ // Use a sequence of nextSibling or previousSibling to reflect your markup
var textbox = checkbox.previousSibling;
textbox.disabled = !checkbox.checked;
textbox.value = checkbox.checked?'1':'0';
}
</script>
<fieldset><legend>Products</legend>
....
<input type="text" name="qty5" value="0" /><input type="checkbox" name="prod5" onchange="buyThis(this)" />
....
</fieldset>
}