我有一个包含三个输入元素的表单。其中一个是按钮,第三个是精度,当我点击它时,表单将执行GET请求。但是,在请求之前我想要提示确认门票数量,在这里,如果我按下确定,请执行GET请求。这是可能的?谢谢 这里有我的HTML代码:
<FORM NAME="formTicket" target="_blank" ACTION='http://localhost:8080/movies/ticket' METHOD="GET" >
<input id="totalTickets" name="numb" type="text" placeholder="Insert number of ticket" size="5" maxlength="1" style="margin-right:20px" /></input>
<input id="totalTicket" name="id" type="hidden" size="5" maxlength="1" style="margin-right:20px" >
<script>
var param = location.search.split('id=')[1];
document.getElementById('totalTicket').value = param;
</script>
</input>
<input type="submit" class="dettagliButton" id="stmp" value='Ticket' style="margin-left:2px">
<script>
var number = prompt("Please enter the number of tickets", "Insert the number here");
document.getElementById('totalTickets').value=number;
</script></input>
</FORM>
答案 0 :(得分:0)
我在mplungjan找到了解决方案,所以我有这个:
<FORM NAME="formTicket" target="_blank" ACTION='http://localhost:8080/movies/ticket' METHOD="GET" onsubmit="prompter();">
<input id="totalTickets" name="numb" type="text" placeholder="Insert number of ticket" size="5" maxlength="1" style="margin-right:20px" />
</input>
<input id="totalTicket" name="id" type="hidden" size="5" maxlength="1" style="margin-right:20px" >
<script>
var param = location.search.split('id=')[1];
document.getElementById('totalTicket').value = param;
</script>
</input>
<input type="submit" class="dettagliButton" id="stmp" value='Ticket' style="margin-left:2px">
<script>
function prompter(){
var number = prompt("Please enter the number of tickets", "Insert the number here");
document.getElementById('totalTickets').value=number;
}
</script></input>
</FORM>
答案 1 :(得分:0)
看到你的解决方案,我建议这样做 - 不确定你想要隐藏的参数:
<!DOCTYPE html>
<html>
<head>
<title>Tickets</title>
<script>
window.onload=function() {
var param = location.search.split('id=')[1];
document.getElementById('totalTicket').value = param;
document.getElementById('formTicket').onsubmit=function() {
var tck = document.getElementById("totalTickets").value;
if (!tck) {
alert("Please enter number of tickets");
document.getElementById("totalTickets").focus();
return false;
}
return confirm("You are ordering the following number of tickets:"+tck+", correct?");
}
}
</script>
</head>
<body>
<form id="formTicket" target="_blank" ACTION='http://localhost:8080/movies/ticket'>
<input id="totalTickets" name="numb" type="text" placeholder="Insert number of tickets" size="5" maxlength="1" style="margin-right:20px" />
<input id="totalTicket" name="id" type="hidden" />
<input type="submit" class="dettagliButton" id="stmp" value='Ticket' style="margin-left:2px" />
</form>
</body>
</html>