Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery html pass a value as third parameter

Is there a way I can pass from an input html tag and append it to a link url ?

 <input type="text" name="job_card_id_payment"
        id="job_card_id_payment"
        class="job_card_id_payment form-control"/>
 <a class="btn btn-success pull-right" 
    id="submit_payment_link" 
    href="<?php echo base_url(); ?>operations/submit_payment">
   <i class="fa fa-credit-card"></i>Submit Payment
 </a>

I want to pass the value from the input name job_card_id_payment to the end of the link url so that it can be like this one :

<?php echo base_url(); ?>operations/submit_payment/1

How can I do it?

like image 425
H Dindi Avatar asked Aug 04 '26 14:08

H Dindi


1 Answers

The solution is to extract the value from input tag and update the URL:

$('#submit_payment_link').click(function(e) {
  // Getting input value.
  var value = $('#job_card_id_payment').val();
  // Getting current link URL.
  var href = $(this).attr('href');
  // Checking for slash at the end and updating URL.
  href += ('/' == href.slice(-1) ? '' : '/') + value;
  // Setting updated URL.
  $(this).attr('href', href);
});
like image 152
Valentin Podkamennyi Avatar answered Aug 07 '26 03:08

Valentin Podkamennyi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!