The best thing to do is set up the markup to be more friendly to the needs of your code. However, if you do not, you can do something like this:
$('input:checkbox').each(function() { var cb = this; $('#h' + cb.id.replace(/^g/, '')).val(cb.checked ? 'Yes' : 'No'); });
Personally, I don't like doing gymnastics with id values; I would establish the relationship between the βgβ and βhβ fields more explicit, using the βdata-β attributes or otherwise, grouping the elements in a specific way (inside a <span> with a specific class, or something else meaningful). I also don't like to pollute the markup, but usually a good balance can be found when what you do makes sense in general.
source share