John Davidson

javascript - i want to pass value of var file_id in appended html in href but it consider as a string

0 comments
Message:


<div id="invite_popup">

</div>

$(".invite_button2").click(function(){
var file_id = $(this).data("id");

//alert(file_id);

var popup2 ='<div id="invite_popup2" class="accourdians_poup invite_popup2">'+
'<ul>'+
'<li><a href="#">Rename</a></li>'+
'<li><a href="{{ route("dashboard.deletefile", ["file_id"=>'+file_id+']) }}">Delete</a></li>'+
'<li><a href="{{ route("dashboard.downloadfile", ["file_id"=>'+file_id+']) }}">download</a></li>'+
'</ul>'+
'<div>';

$("#invite_popup").append(popup2);


$(".invite_popup2").show();

});

when am click on <a> delete</a>
it shows me like: http://localhost/driveProject/deletefile/+file_id+

i want to print value of file_id in url.
please help me i'll be very thankfull.



My Answer:
You can pass the value of the `file_id` variable in the href attribute by concatenating it with the rest of the HTML string. Here's an example:

javascript
var file_id = 123; // Assuming file_id has a value of 123

// Create a new anchor element with the href attribute containing the value of file_id
var anchor = document.createElement('a');
anchor.href = 'https://example.com/file/' + file_id; // Concatenate file_id with the URL

// Append the anchor element to a container element
document.getElementById('container').appendChild(anchor);


In this example, the value of `file_id` is concatenated with the URL in the `href` attribute of the anchor element before appending it to the container element. This way, the value of `file_id` is passed as part of the href attribute.

Rate this post

3 of 5 based on 2735 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us