可以删除部分代码:
<input type="hidden" id="alt_date" name="selArrivalDate" value='<?php $datetime = new DateTime('tomorrow'); echo $datetime->format('Ymd'); ?>' />
提交按钮#bookingSubmitBtn2
?
此处的表格:
$(document).ready(function() {
$("#bookingSubmitBtn").click(function() {
if ($("#children").val() == "") {
$("#children").remove();
}
$("#bookingForm").submit();
});
});
<form name="buchenForm" id="bookingForm" method="get" action="searchresult1.php">
<div>
<input type="text" id="datepicker" value='<?php $datetime = new DateTime('tomorrow'); echo $datetime->format('d/m/Y'); ?>' class="form-control" />
<input type="hidden" id="alt_date" name="selArrivalDate" value='<?php $datetime = new DateTime('tomorrow'); echo $datetime->format('Ymd'); ?>' />
</div>
<div class="form-group">
<button type="submit" id="bookingSubmitBtn1" formaction="searchresult1.php">Search 1</button>
</div>
<div class="form-group">
<button type="submit" id="bookingSubmitBtn2" formaction="searchresult2.php">Search 2</button>
</div>
</form>
答案 0 :(得分:0)
您可以尝试此DEMO LINK HERE https://jsfiddle.net/e6u6ytm3/1/
HTML
<form name="buchenForm" id="bookingForm" method="get" action="searchresult1.php">
<div>
<input type="text" id="datepicker" value="<?php $datetime = new DateTime('tomorrow'); echo $datetime->format('d/m/Y'); ?>" class="form-control" />
<input type="hidden" id="alt_date" name="selArrivalDate" value="<?php $datetime = new DateTime('tomorrow'); echo $datetime->format('Ymd'); ?>" />
</div>
<div class="form-group">
<button id="bookingSubmitBtn1" formaction="searchresult1.php">Search 1</button>
</div>
<div class="form-group">
<button id="bookingSubmitBtn2" formaction="searchresult2.php">Search 2</button>
</div>
</form>
JS
$(document).ready(function() {
$("#bookingSubmitBtn2").click(function() {
var hiddenElement = $('#bookingForm').find('input[name="selArrivalDate"]');
console.log(hiddenElement);
if (hiddenElement) {
$(hiddenElement).remove();
}
$("#bookingForm").submit();
});
});