简体   繁体   English

不使用 jquery 和 jsp 检索存储在克隆文本框中的值

[英]Not retrieving the value stored in the cloned text boxes using jquery and jsp

Script for cloning, removing and submitting the data in the text boxes to the next jsp page SCRIPT:用于克隆、删除文本框中的数据并将其提交到下一个 jsp 页面 SCRIPT 的脚本:

<script type="text/javascript">

    var x = 0;
    var regex = /^(.*)(\d)+$/i;
    var cloneIndex = $(".clonedInput").length;

    function count()
    {
    x += 1;
    document.getElementById( "counting" ).value = x;
    }

    function remo()
    {
    x -=1;
    document.getElementById( "counting" ).value = x;
    }

// BUTTON for CLONING the rows :
$("button.clone").live(
        "click",
        function() {
            $(this).parents(".clonedInput").clone().appendTo(
                    ".clonedOutput").attr("id", "clonedInput" + cloneIndex)
                    .each(function() {
                        var id = this.id || "";
                        var match = id.match(regex) || [];
                        if (match.length == 3) {
                            this.id = match[1] + (cloneIndex);
                        }
                    });
            cloneIndex++;
        });

// BUTTON for REMOVING the selected row :

$("button.remove").live("click", function() {
    $(this).parents(".clonedInput").remove();
});

//BUTTON for submitting the form

$("button.submit").live("click", function() {
    document.getElementById("form1").action = "FooServlet";
    document.getElementById("form1").submit();
});

FORM and BUTTONS :表格和按钮:

<div class="clonedInput">

        <div>

            <form id="form1" method="get">
                <table>
                    <tbody id="DuplicateTable">
                        <tr id="rowToClone">
                            <td><input type="text" name="ID0" value="1" /></td>
                            <td><input type="text" name="ID1" /></td>
                            <td><input type="text" name="ID2" /></td>
                            <td><input type="text" name="ID3" /></td>
                            <td><input type="text" name="ID4" /></td>
                            <td><input id ="counting" type = "text"/></td>
                        </tr>
                    </tbody>
                </table>
            </form>
        </div>
        <div class="actions">
            <button class="clone" onclick = "count()">Clone</button>
            <button class="remove" onclick = "remo()">Remove</button>
            <button class="submit" >Submit</button>

        </div>

    </div>
    <div class="clonedOutput"></div>

code for getting data in next jsp page :在下一个jsp页面中获取数据的代码:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            PrintWriter out = response.getWriter();    
            out.println("Id: " + request.getParameter("ID0"));
            out.println("TestCases: "+ request.getParameter("ID1"));
            out.println("DataType: "+ request.getParameter("ID2"));
            out.println("Variable: "+ request.getParameter("ID3"));
            out.println("Keywords: "+ request.getParameter("ID4")); 
            out.println("count is " + request.getParameter("counting"));
    }

The problem which i am facing is that, on pressing the submit button, i am getting the value stored only in the first textbox, i am not getting the values stored in the cloned textboxes.... Can somebody help me in getting the values stored in the cloned textboxes???我面临的问题是,在按下提交按钮时,我只得到存储在第一个文本框中的值,我没有得到存储在克隆文本框中的值......有人可以帮助我获取值吗存储在克隆的文本框中???

Each clonedInput contains its own form, all with the form1 ID.每个clonedInput包含自己的表单,所有表单都带有form1 ID。 When you then submit, you're selecting the element with the form1 ID, but since there are multiple, the browser will pick one somehow and use that.当您然后提交时,您选择了具有form1 ID 的元素,但由于有多个元素,浏览器会以某种方式选择一个并使用它。 It'll then submit that one form.然后它会提交那个表格。 Not all of them.不是所有的人。 If you want to receive all of the data, pull the form up to a higher level so there's one form holding all of the inputs.如果您想接收所有数据,请将表单拉到更高级别,这样一个表单就可以保存所有输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM