gpt4 book ai didi

javascript - 使用“添加更多表单”按钮创建多个表单

转载 作者:行者123 更新时间:2023-11-28 06:37:25 25 4
gpt4 key购买 nike

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

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>

这是 Action 形式。

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);
}

how can I make a multiple form? enter image description here

最佳答案

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

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

关于javascript - 使用“添加更多表单”按钮创建多个表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34148029/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com