Question

Here is my HTML:

<tr>
                        <td colspan="2" class="borderBottomCell">
                          <div class="benefitInfo" style="WIDTH: 99%! important;">
                            <asp:DropDownList runat="server" ID="ddlbc1"  />
                            <asp:Label runat="server" ID="lblbc1" />
                            <asp:Literal runat="server" ID="spcbc1" Text="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" />
                            <asp:Label runat="server" ID="bd1" />
                            <asp:HiddenField runat="server" ID="hdnbc1"  /> 
                          </div>
                        </td>
                        <td class="borderBottomCell2">
                            <asp:TextBox runat="server" ID="amt1" CssClass="transparentTextBox amount" Width="60px" Columns="9" />
                        </td>
                        <td class="borderBottomCell2">
                            <asp:TextBox runat="server" ID="int1" CssClass="transparentTextBox" Width="60px" Columns="9" />

                        </td>
                    </tr>

I am trying to get a reference to textbox amt1. I need this in a loop as this is just one row from a table. I need to loop through the dropdowns and if the selectedIndex is greater than zero ( > 0 ) The amount textbox needs to have an amount greater than zero ( > 0 ). I will implement dataType validation in the future, currently I just need to know how to get to the relevant textbox withing my loop.

I have this code so far....

$(".benefitInfo select").each(function() {
    var ddl = $(this);

});

What is the best way to accomplish this? Should I get a ref to the parent().parent().next().find(":input") ... Or something to that effect maybe?

Was it helpful?

Solution

This should work:

$(".benefitInfo select").each(function() {
    var ddl = $(this);
    var amtTxt = ddl.closest('tr').find('.amount');
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top