开发者

Add and retrieve text boxes in jsp

I want to add textbox dynamically in jsp page on "Add Row" button click. I have written java script to add it. No issues with that. But I am not able to retrieve those values in Servlet page. Any ideas?

Here is the script:

function addRow(tableID) {

        var table = document.getElementById(tableID);

        var rowCount = table.rows.length;
        var row = table.insertRow(rowCount);

        var cell1 = row.insertCell(0);
        var element1 = document.createElement("input");
        element1.type = "checkbox";
        cell1.appendChild(element1);

        var cell3 = row.insertCell(1);
        var element2 = document.createElement("input");
        element2.type = "text";
        cell3.appendChild(element2);

        var cell3 = row.insertCell(2);
        var element3 = document.createEl开发者_JAVA技巧ement("input");
        element3.type = "text";
        cell3.appendChild(element3);

         var cell4 = row.insertCell(3);
        var element4 = document.createElement("input");
        element4.type = "text";
        cell4.appendChild(element4);

    }

And here is the jsp where script is called:

<INPUT type="button"
    value="Add Row" onclick="addRow('dataTable')" />


You need to specify the name attribute. It becomes the request parameter name.

You can just give them all the same name.

element.name = "foo";

Or if you want to "respect" IE6/7 users as well

document.createElement('<input type="text" name="foo">');

(jQuery makes it all easier and better crossbrowser compatible)

Then you can access them all as follows in the servlet

String[] foos = request.getParameterValues("foo");

They will appear in the order as they appear in the HTML DOM tree.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜