beny lim
beny lim

Reputation: 1304

Passing form value to javascript url

I have a form that will collect input from the user and it consist of a button. Once a user click on the button, a pop up message will be shown.

I would like to post the form inputs to the url stated in the 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>

Upvotes: 5

Views: 365

Answers (2)

Tiberiu C.
Tiberiu C.

Reputation: 3513

You can either create an Ajax request and on success to redirect the page or you can submit a form as in the old days.

If you can alter the HTML, than wrap the inputs into a form with the action set to processEditBookSeat.php and set also an ID like "bookSeatForm" to it so its easyer to find in js side.

Then modify the script like so:

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

Further if this method suits you why not use the default form behaviour and change the #alert element to a submit input ? That is up to you.

Upvotes: 1

Niki van Stein
Niki van Stein

Reputation: 10724

If you want to submit the form using post to a specific adress and therefor direct to this address use

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

If however you want to post it in the background use

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

Upvotes: 2

Related Questions