javascript - remove hidden field on submit 2nd button via js -


it's possible remove part of code:

<input type="hidden" id="alt_date" name="selarrivaldate" value='<?php $datetime = new datetime('tomorrow'); echo $datetime->format('ymd'); ?>' /> 

on submit button #bookingsubmitbtn2?

the form here:

$(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> 

you can try 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();         });     }); 

Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -