在我的網站中,我從數據庫中檢索多個先前保存的地址,並在我的網站上顯示它們。現在,用戶可以選擇其中的任何一個,所選地址的數據將被髮送到下一個頁面以插入到數據庫中。具有相同表單名稱的多個表單。但我想發送正在選擇的表格值
http://tinypic.com/r/2lj70i9/5
我的JSP代碼來獲取地址:
<a href="javascript:next()">
<div class="address1">
<form name="form2" method="post">
<input name="name" type="text" readonly="readonly" value="<% out.print(x1); %>" style="font-weight: bold;" />
<input name="address" type="text" readonly="readonly" value="<% out.print(x2);%>"/>
<input name="city" type="text" readonly="readonly" value="<% out.print(rs1.getString("city"));%>"/>
<input name="state" type="text" readonly="readonly" value="<% out.print(rs1.getString("state"));%>"/>
<input name="pin" type="text" readonly="readonly" value="<% out.print(rs1.getString("pin"));%>"/>
<input name="phone" type="text" readonly="readonly" value="<% out.print(rs1.getString("mob"));%>"/>
</form>
<div class="selectLine">Click to Select</div>
</div>
</a>
,我的JavaScript是:
function next()
{
var f=document.forms["form2"];
f.method="post";
f.action='checkout3.jsp';
f.submit();
}
但問題是什麼,我只選擇頂部地址已經被獲取到下一頁。
你有沒有考慮過你的表格有獨特的名字?然後它應該在提交時提交正確的表格。 – thebreiflabb 2013-05-05 06:42:02
表單值是從數據庫動態接收的。這使得所有的表格都有一個共同的名字。 – 2013-05-05 06:49:48