In a dynamic html table with each row containing comboboxes, I need to do change of the a combobox in a column of a row, if it matches a value i need to disable a combobox in a column of same row using jquery and jsp. How to select the index of a table in jquery. Our version of jquery is 1.10.
Here is the JSP file
<table id="conditionTable">
<thead>
<tr>
<th>Country</th>
<th>State</th>
</tr>
</thead>
<tbody>
<c:forEach items="${actionBean.hosptialLocation.diseaseReported}" var="hospLocationArea" varStatus="counter">
<tr>
<td>
<stripes:select id="countryCombobox" name="hosptialLocation.countriesList[${counter.index}].shortname" class="hdp-combobox countriesCombobox"> <stripes:option label="" value="" /> <stripes:options-enumeration enum="data.enums.Country.shortname" label="description"/>
</stripes:select>
</td>
<td>
<stripes:select id="stateCombobox" class="hdp-combobox required statesCombobox" name="hosptialLocation.statesList[${counter.index}].name"> <stripes:option label="" value="" /> <stripes:options-collection collection="${requestScope.stateNames}" label="Description" value="id" sort="shortDescription"/>
</stripes:select>
</td>
</tr>
</c:forEach>
</tbody>
</table>
js file is
$(document).ready(function() {
$(".countryCombobox").combobox({
select : function() {
var selectedValue = $(this).val();
var row = $(this).closest('tr');
var statesCombobox = row.find('.statesCombobox');
if (selectedValue == 'US') {
$("#stateCombobox").parent().find("input.ui-autocomplete-input").autocomplete("option", "disabled", true).prop("disabled",true);
$("#stateCombobox").parent().find("a.ui-button").button("disable");
} else {
alert("Please select the correct option");
}
});
This code works on first row only, whatever changes are being made and when using the class name all the comboboxes are being disabled.
1