jQuery: populating checkboxes dyn. from select dropdown

this is for a test, am not sure what they mean by “do not hard-code the resulting quarter years in the javascript”:

<select id=“ddQuarters”>
<option value=“1/2010”>January 2010</option>
<option value=“3/2010”>March 2010</option>
<option value=“5/2010”>May 2010</option>
<option value=“7/2010”>July 2010</option>
<!-- etc –>

When a user selects a date from the investment cycle drop-down box, the subsequent investment values must display the next three fiscal quarters. (e.g. for “January 2010”, the subsequent quarters will be Q2 2010, Q3 2010, Q4 2010; for “June 2010”, the subsequent quarters will be Q3 2010, Q4 2010, Q1 2011.)

Do not hard-code the resulting quarter years in the javascript. (empahsis mine…:wink:

The subsequent quarters should be presented with checkboxes which are all unchecked.

checkboxes in markup:

&lt;input id="checkbox1" type="checkbox" value="" /&gt;&lt;label class="chkbx" for="checkbox1"&gt;&lt;/label&gt;&lt;br /&gt;
&lt;input id="checkbox2" type="checkbox" value="" /&gt;&lt;label class="chkbx" for="checkbox2"&gt;&lt;/label&gt;&lt;br /&gt;
&lt;input id="checkbox3" type="checkbox" value="" /&gt;&lt;label class="chkbx" for="checkbox3"&gt;&lt;/label&gt;

the values to populate the checkboxes (value and label) have to be hardcoded somewhere, no? what am I missing???

thank you…

(‘edit’ feature not working again…)

and, since markup doesn’t change when u set value for chkbx dynamically, how do you check that you have set correct value for the checkbox? (don’t know if it shows in Firebug, since don’t know if code have there now is correct ( $(‘#checkbox1’).attr(‘value’, ‘Q2 2010’); ) and how do I populate label? (<label for=“”…></label> – do I need to give label an id?)

thank you…

Here is an example of something being hard-coded:

function calculateTotal() {
    var total = 0;
    total += 1;
    total += 2;
    total += 3;
    total += 4;
    return total;

The problem with being hard-coded is that it’s not flexible. If you want to start from 5 and add up to 12, you would need to change those additions and add more lines.

Here is an example that is not hard-coded:

function calculateTotal(start, end) {
    var total = 0,
    for (i = start; i <= end; i += 1) {
        total += i;
    return total;
calculateTotal(1, 4);