bipin's avatar
Level 2

how i can pass variable on javascript html object

hello guys i have one javascript here is my code

                $('.view').on('click', function() {
   
   
       var id = $(this).attr("data-id");
 
     
    var $iframe=$('<object data="{{ route('browserview', +id) }}" width="100%" height="600px"></object>'); 

  $("#newname").append( $iframe);

  
    }); 

how i can value value of id into something like this {{ route('browserview', +id) }} +id not working

0 likes
4 replies
topvillas's avatar

Put the url in the data attribute and append the id to it. Javascript has no idea what those blade delimiters are or what the route function is.

J_shelfwood's avatar

Everything between the {{}} is PHP, you won't be able to use your javascript variable there. You'd be better off just typing out the route url manually. Unless you have the id javascript variable available in your php, then you could

var $iframe=$('<object data="{{ route('browserview', $id) }}" width="100%" height="600px"></object>'); 
bipin's avatar
bipin
OP
Best Answer
Level 2

i solve my issue by this here is solution

          var url= "{{ url('browserview') }}"+"/"+id;
 
    var $iframe=$('<object data="'+url+'" width="100%" height="600px"></object>'); 

  $("#newname").append( $iframe);

Please or to participate in this conversation.