表格和按钮
<tr>
<td id="tds<%=i%>"><%=trainType%></td>
<td><%=seat1%></td>
<td><%=seat2%></td>
<td><%=seat3%></td>
<td id="tdss<%=i%>"><%=startStation%></td>
<td id="tdsss<%=i%>"><%=endStation%></td>
<td><input type="button" value="一等座购票" class="submit-button" style="font-size: 10px" onclick="buyFirst(<%=i%>)" id=""></td>
<td><input type="button" value="二等座购票" class="submit-button" style="font-size: 10px"></td>
<td><input type="button" value="三等座购票" class="submit-button" style="font-size: 10px"></td>
</tr>
隐藏的表单
<%--用以传输js的值 火车票的有关信息--%>
<form action="http://localhost:8080/TrainTicketingSystem/buyTickets.jsp" style="display: none" id="budeyi">
<input type="text" name="trainType" value="" id="trainType_js">
<input type="text" name="start_station_name" value="" id="start_station_name_js">
<input type="text" name="end_station_name" value="" id="end_station_name_js">
</form>
传值的js方法
<script>
function check_before() {
var myselect=document.getElementById("start");
var index=myselect.selectedIndex;
var city1 = myselect.options[index].text;
var myselect2=document.getElementById("end");
var index2=myselect2.selectedIndex;
var city2 = myselect2.options[index2].text;
if (index==index2){
alert("始发站和终点站不能相同!请重新选择")
}else {
document.getElementById("startStation").value = city1;
document.getElementById("endStation").value = city2;
document.getElementById("submit_form").submit();
}
}
function buyFirst(i) {
var index = i;
var trainType_js = document.getElementById("tds"+index).innerText;
var start_station_name = document.getElementById("tdss"+index).innerText;
var end_station_name = document.getElementById("tdsss"+index).innerText;
document.getElementById("trainType_js").value = trainType_js;
document.getElementById("start_station_name_js").value = start_station_name;
document.getElementById("end_station_name_js").value = end_station_name;
document.getElementById("budeyi").submit();
<%
if (namePeople!=null&&!namePeople.equals("null")){
String trainType = request.getParameter("trainType");
String start_station_name = request.getParameter("start_station_name");
String end_station_name = request.getParameter("end_station_name");
System.out.println("********************"+trainType+start_station_name+end_station_name);
%>
<%
}
else {
%>
alert("请先登录!!!");
<%
}
%>
}
</script>