Techsavy
asked on
set src attribute to a javascript function
Hi,
What I am trying to do is build a dynamic url for my src attribute in img element. such as:
<img id="visionimage" src="javascript:getImageUr l('visioni mage','vis ion.jpg')" alt="vision" /><span>Vision</span>
where:
function getImageUrl(imagetitle)
{
var siteUrl = getSiteUrl();
var imageUrl = siteUrl + "/SiteAssets/images/" + imagetitle;
return imageUrl;
}
but this is not working. How to achieve this?
Please help!
What I am trying to do is build a dynamic url for my src attribute in img element. such as:
<img id="visionimage" src="javascript:getImageUr
where:
function getImageUrl(imagetitle)
{
var siteUrl = getSiteUrl();
var imageUrl = siteUrl + "/SiteAssets/images/" + imagetitle;
return imageUrl;
}
but this is not working. How to achieve this?
Please help!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi leakim
Unfortunately, I can't use data attributes as I am using IE 8 and it has no HTML5 support. I have to rely on native javascript.
Unfortunately, I can't use data attributes as I am using IE 8 and it has no HTML5 support. I have to rely on native javascript.
You can still use them, just means your page won't validate.
ASKER
Thank you...I will give that a try.
Why don't you just run the js when the page is loaded. Storing the image name in data attribute.