#How do you pass a javascript variable to this?
14 messages · Page 1 of 1 (latest)
You'd find the element by giving it an id, and then you could modifying the source attribute that way.
document.getElementById("img_id").src = "awesome.png";
can i do that in jquery like this?
$('#img_id').src="awesome.png";
$('#pfp').on('input', function() {
var data = $("#pfp").val();
$("#pPfp").src = data;
})
```it doesnt seem to recognise .src, atleast i think
"pfp" is the id of the file input
"pPfp" is the id of the img element
i want it so that when the user selects an image that image shows up
so i used alert() to display "data" here, why does it say fakepath?? how do you get the real path?
The fakepath note there is the security implementation of your browser. Some browsers have a security feature that prevents JavaScript from knowing your file's local full path.
well then how am i supposed to display the image if i dont know the actual path?
Upload it, and then display it