0

i am trying to pass image from javascript to apex:image tag but its not passing to apex:image tag it will passing to html tag why its not passing.. Thanks in Advance..

<apex:page >
<apex:form id="form">
<apex:image id="icon" width="50" height="50" />
</apex:form>

<img id="myImg" width="107" height="98"/>

<button onclick="myFunction()">Showimage</button>

<script>
function myFunction() {
 var imageicon = "{!URLFOR($Resource.icon)}";
   document.getElementById("myImg").src = imageicon;
   document.getElementById('!$Component.form.icon').value= imageicon;
   }
</script>
</apex:page>
1
  • Hi, I am facing a similar issue can you tell me how you fixed it?
    – SFDC
    Feb 11, 2020 at 11:15

1 Answer 1

0

Visualforce renders into HTML, so you still have to follow the rules of HTML. In other words, you still use src, not value, as you're trying to do. As a side note, you may have forgotten the curly braces for the merge field. The following should work:

document.getElementById('{!$Component.form.icon}').src = imageicon;

You must log in to answer this question.