1

I now have an asp button in a gridview which I can toggle the text from "Add" to "Remove". Now what I would like is either jquery or javascript to loop through all the rows (or inquire all rows) to determine if any buttons have been toggled (they would have text of "Remove" since the default is "Add"). I don't necessarily need to loop through and process anything, I just want to hide a div if no buttons have been toggled to text of "Remove". The user may have toggled the buttons to "Remove" and back to "Add". So I need to know if at least one button text is currently "Remove".

Here is my templated asp button definition:

<asp:TemplateField HeaderText="Prior <br /> Downld" HeaderStyle-ForeColor="White" > 
  <ItemTemplate >
    <asp:Button id="btnBuy" runat="server" OnClientClick="btnBuyToggle(this); return false;" Text="Add" CssClass="buyButton" Visible='<%# Eval("SORD_ShowBuyButton") %>' />
  </ItemTemplate>
<HeaderStyle Width="7%" />
<ItemStyle CssClass="sessionOrderDownloadItems" VerticalAlign="Middle" HorizontalAlign="Center" />
</asp:TemplateField>

Anyway, I am hoping for maybe a jquery selector looking for text = "Remove", but I am not sure how to construct it.

Note: Working result is this:

       if ( $("input[value=Remove]").length == 0 ) {
            $(".divDownloadHeaderClass").show();
            $(".divPurchaseHeaderClass").hide();
          }
        }
James Randall
  • 41
  • 1
  • 8

1 Answers1

0

I think this would work:

if ( $("input[value=Remove][type=submit]").length > 0 ) {
    $(".divDownload").hide();
}

Hope it helps!

Juan Leung
  • 346
  • 4
  • 13
  • In other words I want to hide a div If any buttons have text of "Remove". As follows: if "Some jquery says I have at least 1 button text "Remove" " { $(".divDownload").hide();} – James Randall May 05 '12 at 02:37
  • Also, I reversed the logic so that if none of the buttons have a text value of "Remove", then I hide my div. I had misstated that originally. Thanks – James Randall May 06 '12 at 00:52
  • I don't quite sure what's the type of input a asp.net button generate, but could be a type=submit, so just change :button to :submit if still doesn't work, can you post the generated html code of the button? – Juan Leung May 06 '12 at 00:58
  • I am using an older version of jquery 1.3.1 so it is possible an upgrade would help but that sounds like a pretty basic thing functionally so I wouldn't think that to be the reason. But FYI – James Randall May 06 '12 at 01:54
  • That's weird, that feature is in JQuery since ver. 1.0, but we can try something else, I updated the code, try it and let me know, btw mark my answer like the right answer would be nice too ;) – Juan Leung May 06 '12 at 04:08
  • That's the ticket! Works like a charm. This is great to know how to code this. Thank you so much for sticking with it. Jim – James Randall May 06 '12 at 14:44