Search code examples
javascriptimagesrc

JS + HTML, get src using javascript


lets say I have an image being displayed using the code:

<img src="image.png"/>

I would like to define the src using javascript, how would you do something like

<script>
function getImage ()
{
   return "image.png";
}
</script>
<img src="Javascript:getImage()"/>

UPDATE:

I need it to work with the divx player, getting the video url paramater via javascript

<object classid="clsid:*************" width="320" height="260" codebase="http://go.divx.com/plugin/DivXBrowserPlugin.cab"> 
                <param name="custommode" value="none" /> 
                <param name="autoPlay" value="true" /> 
                <param name="src" value="Javascript:GetURL()" /> 
                <embed type="video/divx" src="Javascript:GetURL()" custommode="none" width="850" height="400" autoPlay="true"  pluginspage="http://go.divx.com/plugin/download/"> 
                </embed> 
            </object> 

anyone have any ideas for this?


Solution

  • You should give your tags individual IDs, then do

    src = 'image.png';
    document.getElementById('param1').setAttribute('value', src);
    document.getElementById('embed1').setAttribute('src', src);
    
     <param id="param1" name="src" value="Javascript:GetURL()" /> 
                    <embed id="embed1" type="video/divx" src="Javascript:GetURL()" custommode="none" width="850" height="400" autoPlay="true"  pluginspage="http://go.divx.com/plugin/download/">