I have a table populated from a selection from a dropdownlist. If the status of any of the items in the table is anything other than ‘success’, I want to disable a button on the page, otherwise I enable it. I have a change event handler with the following:
function enableButton() {
$(".myButton").attr("disabled", true);
$("td.tdStatus").each(function() {
if ($(this).text() == "SUCCESS") {
$("input.myButton").attr("disabled", false);
return false;
}
});
}
$(function() {
$("#myList").change(enableButton);
});
On the first selection of an item from the dropdown, I’m getting into the event handler but $("td.tdStatus").each(function() isn’t finding anything. When I then make a subsequent change to the dropdownlist, the button gets enabled/disabled as I’d expect. Any ideas why the first change isn’t working?
HTML is as follows:
<ItemTemplate>
<tr>
<td runat="server" id="tdName"><%# Eval("Name") %></td>
<td class="tdStatus"><%# Eval("Status") %></td>
</tr>
</ItemTemplate>
Thanks
Just to give an update, the tab the data is loaded into has a function that is bound to the tabsload event:
$(“#tabContent”).bind(‘tabsload’, tabLoaded);
Inside tabLoaded I put a call to the enableButton() function and that’s got it working ok, with the data completely loaded before the function fires. Thanks all for your help, apologies for missing out the key information in the original post!