I have 5 rows that each have an identical selection element (or
dropDownList) in the first cell of each row. Choosing a value from
that populates the values in another selection element.
How can I populate the selection items, and in a way that is less
verbose than the "brute force" approach here:
-
$(document).on("change",
'[id$=ddlPaymentType1]', function () {
var value = $(this).val();
if (value == '1') {
$('[id$=ddlAccount1]').text("Replace this
with the values for selection 1");
}
else if (value == '2') {{
$('[id$=ddlAccount1]').text("Replace this
with the values for selection 2");
}
else if (value == '3') {{
$('[id$=ddlAccount1]').text("Replace this
with the values for selection 3");
}
else if (value == '4') {{
$('[id$=ddlAccount1]').text("Replace this
with the values for selection 4");
}
else if (value == '5') {{
$('[id$=ddlAccount1]').text("Replace this
with the values for selection 5");
}
else if (value == '6') {{
$('[id$=ddlAccount1]').text("Replace this
with the values for selection 6");
}
/* TODO: Add the rest (not value=11, as
that is the "VENDORS" category item (not a
real selection in itself)) */
});
With the above, I would have to respond to about 20 different
values (only six are shown), and I would have to code five
identical-except-for-the-ID-arg and val functions. IOW, I would also need
-
$(document).on("change",
'[id$=ddlPaymentType2]', function () {
. . .
});
...etc (up through ddlPaymentType5).
What is a better way to accomplish this?