为文本字段创建动态ID并获取文本字段的值?

时间:2014-04-14 12:54:17

标签: jquery jsp servlets

我正在使用servlet本身的复选框构建表,并且在选择复选框时尝试分配文本字段和id,在分配id后我试图获取复选框选中的文本字段的值但是我无法获得文本字段价值在这里,我已经包含了我的代码,

我的servlet代码是,

PrintWriter out = response.getWriter();
        PreparedStatement distscenarioName = null;
        PreparedStatement minscenariId = null;
        PreparedStatement testcaseName = null;
        String scenari_name = null; 
        Connection connection=DatabaseConnection.getConnection();
        distscenarioName=connection.prepareStatement("select distinct scenario_name from scenario");
        ResultSet rs=distscenarioName.executeQuery();
        out.println("<tr><td><b>");
        out.println("Scenario Name:");
        out.println("</b></td><td><b>");
        out.println("Testcase ID:");
        out.println("</b></td><td><b>");
        out.println("Testcase Name:");
        out.println("</b></td><td><b>");
        out.println("Testcase Description:");
        out.println("</b></td><td><b>");
        out.println("Action:");
        out.println("</b></td></tr>");
        while(rs.next()){
            scenari_name=rs.getString("scenario_name");
            minscenariId=connection.prepareStatement("select min(scenario_id) from scenario where scenario_name =?");
            minscenariId.setString(1, scenari_name);
            ResultSet rss=minscenariId.executeQuery();
            if(rss.next()){
                testcaseName=connection.prepareStatement("select tc_id,tc_desc,tc_name from testcase where scenario_id=?");
                testcaseName.setInt(1,rss.getInt("min(scenario_id)"));
                ResultSet testcaseExe=testcaseName.executeQuery();  
                out.println("<tr><td><h4>");
                out.println(scenari_name);
                out.println("</td></h4><td></td><td></td><td></td><td></td></tr>");
                while(testcaseExe.next()){

                    out.println("<tr><td>");
                    out.println("<td>");
                    out.println(testcaseExe.getInt(1));
                    out.println("</td>");
                    out.println("</td><td>");
                    out.println(testcaseExe.getString("tc_name"));
                    out.println("</td><td>");
                    out.println(testcaseExe.getString("tc_desc"));
                    out.println("</td><td>");
                    out.println("<input type=checkbox class='btnChckBox'>");
                    out.println("</td></tr>");
                }


            }
        }

和我的jquery代码是,

$.ajax({
                        type : "POST",
                        url : "./ScenarioExecutionPage",
                        success : function(result) {
                            /* alert("Length"+result.toString().length); *//*
                                                                             * alert("length"+result.length());
                                                                             */
                            $("#testcaseTable").html(result);                               
                            $("#testcaseTable").show();
                            $("hide7").hide();
                            var par = $(this).parent().parent(); // tr
                            var btnChckBox = par.children("td:nth-child(4)");
                            alert("alert "+btnChckBox);
                            btnChckBox.html("<input type='checkbox' class='btnChckBox'>");
                            $(".btnChckBox").bind("click",editM);
                            // $("#listC").html(result);
                        }
                    });


function editM(){
                    var i="";
                    var par = $(this).parent().parent();
                    var tcDesc = par.children("td:nth-child(3)");
                    var rowCount = $('#testcaseTable tr').length;
                    for(i=0; i<=rowCount; i++){
                        tcDesc.html("<input type='text' disabled='disabled' class='form-control'id='"+i+"' value='"+ tcDesc.html()+"'/>");
                        //var s = $("#tstcsDsc"+i+"").val();
                        alert("TC DESC-->"+$(""+i+"").val());

                    }

0 个答案:

没有答案