收集表单中的单独值并将它们作为一个字符串发布

时间:2016-04-27 15:48:56

标签: javascript php jquery forms

我正在使用此表单

_.isEqual()

我重新设计它看起来像这样 -

new form

我设法使用此代码将日期选择器中的值分成不同的输入

<form onsubmit="return validate();" method="get" action="http://marriott.com/reservation/availabilitySearch.mi" name="fullRatesCalloutForm" target="_blank">
    <h3>Reservations</h3>
          <input type="hidden" value="false" name="clusterSell">
          <input type="hidden" value="YYJMC" name="propertyCode">
          <input type="hidden" value="false" name="isSearch">
          <input type="hidden" value="SrchMod_P" name="WT_Ref">
          <input type="hidden" value="1" name="numberOfNights">
          <input type="hidden" value="" name="groupCode">
          <input type="hidden" value="" name="marriottRewardsNumber">
          <input type="hidden" value="" name="corporateCode">
          <label for="fromDate">Check-in date:</label>
          <br>
          <input value="mm/dd/yyyy" name="fromDate" tabindex="2" onchange="SetFormDate('checkInDate')" id="start-date" class="date-pick dp-applied hasDatepicker" gtbfieldid="1">
          <img class="ui-datepicker-trigger" src="http://www.marriottvictoria.com/images/calendar.gif" alt="Choose date" title="Choose date">
          <br class="clear">
          <label for="toDate">Check-out date:</label>
          <br>
          <input value="mm/dd/yyyy" name="toDate" tabindex="2" onchange="SetFormDate('checkOutDate')" id="end-date" class="date-pick dp-applied hasDatepicker" gtbfieldid="2">
          <img class="ui-datepicker-trigger" src="http://www.marriottvictoria.com/images/calendar.gif" alt="Choose date" title="Choose date">
          <br class="clear">
          <div class="sel">
            <label for="numberOfRooms" class="room">Rooms:</label>
            <br>
            <select name="numberOfRooms" tabindex="7" id="roomNum" gtbfieldid="3">
              <option value="1">1</option>
              <option value="2">2</option>
              <option value="3">3</option>
            </select>
          </div>
          <div class="sel">
            <label>Guests per room:</label>
            <br>
            <select name="numberOfGuests" tabindex="8" id="guestNum" gtbfieldid="4">
              <option value="1">1</option>
              <option value="2">2</option>
              <option value="3">3</option>
              <option value="4">4</option>
              <option value="5">5</option>
              <option value="6">6</option>
            </select>
          </div>
          <input type="submit" value="Check Availability" onmousedown="ga('send', 'pageview', '/ReservationsWidget/Marriott_com');" href="javascript:document.fullRatesCalloutForm.submit();">
        </form>

我现在的问题是我必须将到达和离开日期发送为mm / dd / yy而不是单独的值。我不知道如何在提交

上更改查询字符串

1 个答案:

答案 0 :(得分:1)

如果我理解你正在尝试做什么,你可以像这样创建字符串:

 var datePieces = dateText.split('/');
var month = datePieces[0];
var day = datePieces[1];
var year = datePieces[2];
//define select option values for
//corresponding element
$('select#month').val(month);
$('select#day').val(day);
$('select#year').val(year); }});

return month + '/' + day + '/' + year;