Patrick Lorio
Patrick Lorio

Reputation: 5668

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?

Upvotes: 1

Views: 1593

Answers (3)

Jason Kaczmarsky
Jason Kaczmarsky

Reputation: 1686

You have to assign the image an ID, then use this:

document.getElementById('img_id').src="new_image.jpg";

Upvotes: 1

bozdoz
bozdoz

Reputation: 12860

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/">

Upvotes: 1

Ben
Ben

Reputation: 1302

You can dynamically write in the embed code with the video URL with document.write(), but you should only do this when the page loads.

Upvotes: 0

Related Questions