phillipstack phillipstack - 2 months ago 31
HTML Question

How do I use jsp form element contents (base64, text) as my html image src?

The jsp form contents are already formatted as such:

<form id="textpage"
<textarea name="textbox" id="text">
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAfQAAABkCAYAAABwx8J9AAAcC0lEQVR4nO3dd1SUZ.....
</textarea></form>


I want to click a button on another html page

<button>Load Image!!</button>


and replace an existing image placeholder src="putImageHere.png" with

src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAfQAAABkCAYAAABwx8J9AAAcC0lEQVR4nO3dd1SUZ..."


ALSO !!! The src above must be a variable as it will be different each time its loaded so it cant be hard coded.

Answer

So basically I ended up loading an element with jquery and in the end it was as simple as

$('#elementId').load(URL,data,function(){
    $('#myImage').attr("src", $('#elementId').innerHTML);
});