Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 256
  • Last Modified:

how can I disable button if table row appended was Empty?

I have a create button which disabled at first I want to enable it when the table row has a record, how can i do this? I have jquery here, how can I improved this?

 $("#btnCreateExecutiveShareList").click(function () {
         
            var numberOfRows = $('#AppendedTableEmployeeShare > tbody > tr').length;
            if (numberOfRows == 0 || numberOfRows == "") {
                $("#btnCreateExecutiveShareList").attr("disabled", true)
            }
            else
            {
                $("#btnCreateExecutiveShareList").attr("disabled", false)
            }
        });
0
jabz ayuap
Asked:
jabz ayuap
1 Solution
 
Randy PooleCommented:
What you are doing is fine. If you want to compact it then:
 $("#btnCreateExecutiveShareList").click(function () {
          
            var numberOfRows = $('#AppendedTableEmployeeShare > tbody > tr').length;
            $("#btnCreateExecutiveShareList").attr("disabled", (numberOfRows == 0 || numberOfRows == ""));
        });

Open in new window

0
 
jabz ayuapdevAuthor Commented:
Hi randy what if the number of rows = 0 and the button disabled what if i remove the value, how can i disable it again?
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now