insert checked checkbox values into text field
<p>I have a form with 3 arrays of checkboxes - hummus[], mayo[], jam[]. In the jquery functions below, when the required number of checkboxes are checked the rest of the checkboxes are disabled (this currently works).</p>

<p><strong>Question</strong>: As they are checked, I am also trying to get the checked checkbox values into text field values, hummus1, hummus2, mayo1, jam1 - (these text fields will change to hidden fields for posting when live).
The 2 hummus functions don't work and the mayo and jam functions only return the first checkbox value of the array whether checked or not.</p>

<p>Any help here is much appreciated.</p>

<pre><code>jQuery(function one(){
var max = 2;
var checkboxes = $('input[type="checkbox"][name="hummus[]"]');

checkboxes.change(function(){
var current = checkboxes.filter(':checked').length;
checkboxes.filter(':not(:checked)').prop('disabled', current &gt;= max);

// Trying to insert the 2 checked hummus values from the hummus array into text fields
$('input[type="text"][name="hummus1"]').val($('input[type="checkbox"][name="hummus[0]"]').val());
$('input[type="text"][name="hummus2"]').val($('input[type="checkbox"][name="hummus[1]"]').val());
});
});

jQuery(function two(){
var max = 1;
var checkboxes = $('input[type="checkbox"][name="mayo[]"]');

checkboxes.change(function(){
var current = checkboxes.filter(':checked').length;
checkboxes.filter(':not(:checked)').prop('disabled', current &gt;= max);

// Trying to insert the single checked mayo value into the mayo1 text field
$('input[type="text"][name="mayo1"]').val($('input[type="checkbox"][name="mayo[]"]').val());
});
});

jQuery(function three(){
var max = 1;
var checkboxes = $('input[type="checkbox"][name="jam[]"]');

checkboxes.change(function(){
var current = checkboxes.filter(':checked').length;
checkboxes.filter(':not(:checked)').prop('disabled', current &gt;= max);

// Trying to insert the single checked jam value into the jam1 text field
$('input[type="text"][name="jam1"]').val($('input[type="checkbox"][name="jam[]"]').val());
});
});

jQuery(function uncheck() {
// Uncheck all checkboxes on page load    
$(':checkbox:checked').removeAttr('checked');
})
</code></pre>

<p>The HTML:</p>

<pre><code>&lt;form id="orderProductForm219" name="orderProductForm219" method="post"&gt;
&lt;b&gt;Select any TWO Hummus from this list.&lt;/b&gt; 
&lt;br /&gt;&lt;br /&gt;
&lt;input type="checkbox" name="hummus[]" value="chilli hummus with harissa"&gt; chilli hummus with harissa&lt;br /&gt;
&lt;input type="checkbox" name="hummus[]" value="cumin &amp;amp; lemon oil hummus"&gt; cumin &amp;amp; lemon oil hummus&lt;br /&gt;
&lt;input type="checkbox" name="hummus[]" value="garlic hummus"&gt; garlic hummus&lt;br /&gt;
&lt;input type="checkbox" name="hummus[]" value="pumpkin, fetta &amp;amp; dukkah hummus"&gt; pumpkin, fetta &amp;amp; dukkah hummus
&lt;br /&gt;&lt;br /&gt;
&lt;b&gt;and include ONE Mayonnaise from this list.&lt;/b&gt; 
&lt;br /&gt;&lt;br /&gt;
&lt;input type="checkbox" name="mayo[]" value="aioli"&gt; aioli&lt;br /&gt;
&lt;input type="checkbox" name="mayo[]" value="saffron, dill &amp;amp; mustard mayonnaise"&gt; saffron, dill &amp;amp; mustard mayonnaise&lt;br /&gt;
&lt;input type="checkbox" name="mayo[]" value="wasabi mayonnaise"&gt; wasabi mayonnaise&lt;br /&gt;
&lt;input type="checkbox" name="mayo[]" value="chilli mayonnaise"&gt; chilli mayonnaise&lt;br /&gt;
&lt;input type="checkbox" name="mayo[]" value="caesar dressing"&gt; caesar dressing&lt;br /&gt;
&lt;input type="checkbox" name="mayo[]" value="smoked aioli"&gt; smoked aioli
&lt;br /&gt;&lt;br /&gt;
&lt;b&gt;and include ONE Relish, Jam, Curd or Pesto from this list.&lt;/b&gt; 
&lt;br /&gt;&lt;br /&gt;
&lt;input type="checkbox" name="jam[]" value="middle eastern red pepper &amp;amp; pomegranate pesto"&gt; middle eastern red pepper &amp;amp; pomegranate pesto&lt;br /&gt;
&lt;input type="checkbox" name="jam[]" value="aubergine relish"&gt; aubergine relish&lt;br /&gt;
&lt;input type="checkbox" name="jam[]" value="beetroot relish"&gt; beetroot relish&lt;br /&gt;
&lt;input type="checkbox" name="jam[]" value="tomato &amp;amp; chilli relish"&gt; tomato &amp;amp; chilli relish&lt;br /&gt;
&lt;input type="checkbox" name="jam[]" value="taramasala"&gt; taramasala&lt;br /&gt;
&lt;input type="checkbox" name="jam[]" value="preserved lemons"&gt; preserved lemons&lt;br /&gt;
&lt;input type="checkbox" name="jam[]" value="rasberry &amp;amp; white chocolate jam"&gt; rhubarb, rasberry &amp;amp; white chocolate jam&lt;br /&gt;
&lt;input type="checkbox" name="jam[]" value="apricot, saffron &amp;amp; vanilla bean jam"&gt; apricot, saffron &amp;amp; vanilla bean jam&lt;br /&gt;
&lt;input type="checkbox" name="jam[]" value="apricot &amp;amp; armaretto jam"&gt; apricot &amp;amp; armaretto jam&lt;br /&gt;
&lt;input type="checkbox" name="jam[]" value="rose water &amp;amp; cardamon marmalade"&gt; rose water &amp;amp; cardamon marmalade&lt;br /&gt;
&lt;input type="checkbox" name="jam[]" value="whiskey &amp;amp; ginger marmalade"&gt; whiskey &amp;amp; ginger marmalade&lt;br /&gt;
&lt;input type="checkbox" name="jam[]" value="lemon curd"&gt; lemon curd&lt;br /&gt;
&lt;input type="checkbox" name="jam[]" value="Lemon &amp;amp; passion fruit curd"&gt; lemon &amp;amp; passion fruit curd
&lt;br /&gt;
&lt;input type="hidden" name="productId" value="219" /&gt;
&lt;input type="hidden" name="productTitle" value="Gift Pack" /&gt;
&lt;input type="hidden" name="price" value="1.00" /&gt;
&lt;input type="text" name="hummus1" id="hummus1" value="" /&gt;
&lt;input type="text" name="hummus2" id="hummus2" value="" /&gt;
&lt;input type="text" name="mayo1" id="mayo1" value="" /&gt;
&lt;input type="text" name="jam1" id="jam1" value="" /&gt;
&lt;/form&gt;
</code></pre>
