skip to Main Content

I want to print variable value inside string quote

this is my variable

var id = $(this).val();

how can i print this variable to this string

 $('#button_cetak').html('<a href="{{route('report.pdf',[$user->nip,'//this is place i wanna print'])}}" class="btn btn-warning btn-block"><i class="fas fa-print"></i> Cetak</a>');

thanks

2

Answers


  1. You can do it in two ways.

    • 1. Make use of JavaScript String Literals
    var id = $(this).val();
    $('#button_cetak').html(`<a href="{{ route('report.pdf',[$user->nip,'${id}'])}}" class="btn btn-warning btn-block"><i class="fas fa-print"></i> Cetak</a>`);
    
    • 2. JavaScript dummy replace
    var id = $(this).val();
    var url = `<a href="{{ route('report.pdf',[$user->nip,':id'])}}" class="btn btn-warning btn-block"><i class="fas fa-print"></i> Cetak</a>`;
    url = url.replace(':id', id);
    $('#button_cetak').html(url);
    
    
    Login or Signup to reply.
  2. $('#button_cetak').html('<a href="{{routr('+report.pdf+',[$user->nip,'+id+'])}}" class="btn btn-warning btn-block"><i class="fas fa-print"></i> Cetak</a>');
    

    This would be the correct way to concatenate.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search