使用添加更多表单按钮创建多个表单

时间:2015-12-08 04:30:26

标签: javascript jquery forms jsp

我有多个文本框示例。 但它只能制作一个文本框。 我想用按钮添加表格制作多个表格。这在我的样本中

enter image description here

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript">
function appendRow()
{
   var d = document.getElementById('plus');
   d.innerHTML += "<input type='text' name='nama'><br >";
}
</script>
</head>
<body>
<form action="Crud_insert_multiple" method="POST">
	<input type="button" onclick ="appendRow()" value="Add Text Boxt">
	<table>
	<tr><td>Nama</td><td><div id='plus'></div></td></tr>
	<tr>
	<td></td>
	<td><input type="submit" value="Save"></td>
	</tr>
	</table>
	</form>
</body>
</html>

这是行动表格。

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    Database db = (Database) getServletContext().getAttribute("db");
    String[] a=request.getParameterValues("nama");
    for (int i = 0; i < a.length; i++) {
        try {
            String sql = "insert into user(username) values('"+a[i]+"')";
            db.updateSql(sql);

        } catch (Exception e2) {
            System.out.println(e2);
        }
    }
    getServletContext().getRequestDispatcher("/crud_select.jsp").forward(request, response);
}
  

如何制作多种形式?   enter image description here

1 个答案:

答案 0 :(得分:0)

更新输入名称以接受多个值(在数组中)

d.innerHTML += "<input type='text' name='nama[]'><br >";