形式为循环内表格的行

时间:2018-10-22 13:03:05

标签: javascript forms html-table

我必须制作一个表,其中所有行都必须删除或更新产品价格。我已经编写了以下代码,但是将tr标记显示为无效位置。此外,该表格也不符合要求。

<h1>On Manage Products Page by <% out.println(request.getSession().getAttribute("username"));%></h1>
	<div align="center">
		<script>
			function onSubmitForm()
			{
				System.out.println(document.pressed);
				if(document.pressed == 'delete')
				{
				 System.out.println("delete");
				 document.myForm.action ="deleteProduct.do";
				}
				else
				if(document.pressed == 'update')
				{
				 System.out.println("update");
				  document.myForm.action ="updateProduct.do";
				}
				return true;
			}
		</script>
		<table>
			<thead><tr><th>PRODUCT NAME<th>PRODUCT PRICE<th> DELETE<th COLSPAN="2"> UPDATE
			
				
				
				<% List products=(List)request.getSession().getAttribute("products"); %>
				<c:forEach items="${products}" var="product">
					<form name="myForm" onsubmit="return onSubmitForm();">
						<input type="hidden" name="productID" value="${product.getProductID()}" />
						<tr>
							 
						    <td>${product.getProductName()}
						    <td>${product.getProductPrice()}
							<td><input type="submit" name="operation" onclick="document.pressed=this.value" value="delete"/>
							<td><input type="text" name="updatedPrice"/>
							<td><input type="submit" name="operation" onclick="document.pressed=this.value" value="update"/>
					</form>
				</c:forEach>
			
				
		</table>
	</div>

2 个答案:

答案 0 :(得分:1)

生成的代码存在很多问题:

<table>
  <thead>
    <tr> <-- no closing tag
      <th>PRODUCT NAME  <-- no closing tag
        <th>PRODUCT PRICE <-- no closing tag
          <th> DELETE <-- no closing tag
           <th COLSPAN="2"> UPDATE <-- no closing tag
    <form>  <-- can't be a child of table
      <tr>  <-- not a child of a table/tbody & no closing tag
        <td> <-- no closing tag
        <td> <-- no closing tag
        <td> <-- no closing tag
        <td> <-- no closing tag
        <td> <-- no closing tag
    </form> 
<table>

答案 1 :(得分:0)

别忘了关闭标签。

在您所有表格中,您都缺少结束标记。

例如您的thead行应该看起来像这样:

<thead><tr><th>PRODUCT NAME</th><th>PRODUCT PRICE</th><th> DELETE</th><th COLSPAN="2"> UPDATE</th></tr></thead>