Passing form value in javascript url

I have a form that will collect input from the user and consists of a button. As soon as the user clicks the button, a pop-up message will appear.

I would like to post form input in url specified in javascript.

<div class="live-preview"> <a class="confirm" id="alert"> <input type="submit" name="submit" class="btn btn-common uppercase" value="Edit Booking"> </a> <script> $(".confirm").easyedit(); $("#alert").click(function() { window.location = "processEditBookSeat.php"; }); </script> <input name="workshopSeatLeft" type="hidden" id="workshopSeatLeft" value="<?php echo $resultWorkshopDetail['workshopDetailSeatLeft']?>"> <input name="alreadyBookedSeat" type="hidden" id="alreadyBookedSeat" value="<?php echo $userBookedSeat?>"> <input name="workshopID" type="hidden" id="workshopID" value="<?php echo $getWorkshopID?>"> </div> 
+5
source share
2 answers

If you want to submit fill out the form using a message for a specific address, and therefore use this address

 $('#form').attr('action', "/yoururl").submit(); 

If you want to publish it in the background, use

 $.post(url, $('#form').serialize()); 
+2
source

You can either create an Ajax request, or successfully redirect the page or submit the form as in the old days.

If you can change the HTML than wrap the form inputs with the action set in processEditBookSeat.php and set the ID for it, for example, "bookSeatForm", so it’s easier to find it in the js-side.

Then change the script like this:

  $(".confirm").easyedit(); $("#alert").click(function() { $("#bookSeatForm").submit() }); 

Also, if this method suits you, why not use the default form behavior and change the #alert element to submit input? It depends on you.

+1
source

Source: https://habr.com/ru/post/1233457/


All Articles