javascript
  • html
  • prompt
  • 2016-01-22 91 views 0 likes 
    0

    我有一個包含三個輸入元素的表單。其中一個按鈕是精確度的第三個按鈕,當我點擊它時,表單將執行GET請求。但是,在請求之前我想要一個提示來確認票數,並且在這裏,如果我按OK,請執行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> 
    
    +1

    [使用的Javascript確認取消表單提交]的可能的複製(http://stackoverflow.com/questions/12226701/javascript-using-confirm-to-cancel-form-submission) – mplungjan

    +0

    是的,謝謝你soo !!!現在我發佈解決方案 –

    +0

    沒必要。只是刪除你的問題 - 這是特別有用的,你和其他人可以看看其他 – mplungjan

    回答

    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> 
    
    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>  
    
    +0

    謝謝,但我只發佈了我的代碼的一部分,我已經完成了所有,我不希望一個函數出現在onload的頁面 –

    +0

    你是什麼意思的「出現功能」? – mplungjan

    相關問題