HTML表单重定向

时间:2015-03-18 11:32:43

标签: javascript html forms

我需要以下代码的帮助,我有这个表格,我想通过输入他们的预订参考和姓氏来检索用户预订,当我点击提交时,它将我重定向到航班搜索页面而不是view_reservation页面。一旦提交,它应该使用最后的ref https://example/bookings/m/view_reservation.aspx?PNR=RefNUM

进行此操作

的javascript:

$("button#jamie").click(function() {
   event.preventDefault();
   var value = $( "#userPNR"  ).val();
   var currentURL = window.location.href;
   var gotto = "https://example.com/bookings/m/view_reservation.aspx?"
   var when = "PNR="
   var goUrl = gotto + when + value;
   window.location = goUrl;
})

html:

<form id="frm_RetrieveReservation" data-ajax="false" rel="external" method="post" action="https://example/bookings/m/view_reservation.aspx?">
   <div id="manager_booking" style="">
       <label>Reservation #</label>
       <div class="ui-input-text ui-body-inherit ui-corner-all ui-shadow-inset">
           <input id="userPNR" name="userPNR" type="text" >
       </div>
       <label>Last Name</label>
       <div class="ui-input-text ui-body-inherit ui-corner-all ui-shadow-inset">
           <input id="passengerName" name="passengerName" type="text">
       </div>
       <button  value="Find Reservation"style="width:96%" class=" ui-btn ui-shadow ui-corner-all Submitters" id="jamie">Search</button>             
    </div>
</form>

1 个答案:

答案 0 :(得分:0)

将'event'参数添加到event.preventDefault()的click处理程序中以运行:

$("button#jamie").click(function(event) {