kbvishnu
kbvishnu

Reputation: 15630

Accessing a specific row using Jquery

I am having a table and i am adding rows dynamically in to it using the following code.There is a dialogue box which is having a yes and a no button.The problem is that i need to ask some thing through that dialogue.If the user says no ,it will close the dialogue and the row will be added using after function of j query.But if the user selects yes,I need to make the value of 'au' to be one.The default value is 0.But here ,before showing the popup all rows will be created and au will be zero.How can I get that particular rows and its value. Thanks in advance

 $('#addItem').click(function() {
                                $('#dialog').dialog({
                                autoOpen: true,
                                width: 400,
                                modal: true,
                                resizable: false,
                                buttons: {
                                    "No": function() {
                                        $(this).dialog("close");
                                    },
                                    "Yes": function() {
                                        au = 1;
                                        $(this).dialog("close");
                                    }
                                }
                            });
                          $('#<%= tblEnergy.ClientID %>  tr:last').after(
                                    "<tr>"
                                    + "<td style='display:none'>" + getTextBoxValue('<%=ab.ClientID %>') + "</td>"
                                    + "<td>" + $('#<%=ab.ClientID %> option:selected').text() + "</td>"
                                    + "<td  style='display:none'>" + getTextBoxValue('<%=txtBat.ClientID %>') + "</td>"
                                    + "<td>" + getTextBoxValue('<%=txtReq.ClientID %>') + "</td>"
                                    + "<td><span style='width:100%' class='del'><%= this.DelButtonHtml %></td>"
                                    + "<td style='display:none'><span style='display:none'>" + getTextBoxValue('<%=hdfDept.ClientID %>') + "</span></td>"
                                    + "<td style='display:none'><span style='display:none'>" + getTextBoxValue('<%=hdfLoc.ClientID %>') + "</span></td>"
                                    + "<td style='display:none'><span style='display:none' class='clk'>" + au + "</span></td>"
                                    + "</tr>"
                                );
                                }
                                else {

                                }
                                setTextBoxValue('<%=txtStock.ClientID %>', '');
                                setTextBoxValue('<%=txtBat.ClientID %>', '');
                                setTextBoxValue('<%=txtReq.ClientID %>', '');
                                setTextBoxValue('<%=ddlEnergy.ClientID %>', 0);
                            }
                            else {
                                showStatus(true, "Please specify the Required Quantity");
                            }
                        } else {
                            showStatus(true, "Please specify the Required Quantity");
                        }
                    }
                });

settextBox and gettextbox were userdefined functions in javascript to set or get values in the form

Upvotes: 2

Views: 209

Answers (1)

Hari Pachuveetil
Hari Pachuveetil

Reputation: 10374

The code you've given above is not syntactically complete, so I've clipped out lines that I thought was not relevant to the question. So the answer here is only a guideline as to what can be done with the callback functions on the dialog. With that preface, here is the code:

$('#addItem').click(function() {
    $('#dialog').dialog({
        autoOpen: true,
        width: 400,
        modal: true,
        resizable: false,
        buttons: {
            "No": function() {
                addDynamicRow(0);
                $(this).dialog("close");
            },
            "Yes": function() {
                addDynamicRow(1);
                $(this).dialog("close");
            }
        }
    });
});


function addDynamicRow(auValue) {
    $('#<%= tblEnergy.ClientID %>  tr:last').after(
        "<tr>"
        + "<td style='display:none'>" + getTextBoxValue('<%=ab.ClientID %>') + "</td>"
        + "<td>" + $('#<%=ab.ClientID %> option:selected').text() + "</td>"
        + "<td  style='display:none'>" + getTextBoxValue('<%=txtBat.ClientID %>') + "</td>"
        + "<td>" + getTextBoxValue('<%=txtReq.ClientID %>') + "</td>"
        + "<td><span style='width:100%' class='del'><%= this.DelButtonHtml %></td>"
        + "<td style='display:none'><span style='display:none'>" + getTextBoxValue('<%=hdfDept.ClientID %>') + "</span></td>"
        + "<td style='display:none'><span style='display:none'>" + getTextBoxValue('<%=hdfLoc.ClientID %>') + "</span></td>"
        + "<td style='display:none'><span style='display:none' class='clk'>" + auValue + "</span></td>"
        + "</tr>"
    );
}

Upvotes: 2

Related Questions