I am trying to set background image of a div through prototype javascript.The image_path variable returning exact file location.If I use that variable in setStyle it returning only the variable name not the image.What am i doing wrong?
<script type="text/javascript">// <![CDATA[
function changed()
{
var options=$('first');
if(options.value.endsWith('.jpg'))
{
var image_name=options.value;
var image_path="http://localhost/dev/skin/frontend/default/wireframe/images/"+image_name;
//alert(image_path);
$('firstdiv').setStyle({backgroundImage: 'url(image_path)'});
return;
}
else {
$('firstdiv').setStyle({backgroundColor:options.value});
}
}
// ]]></script>
you’re using
image_pathas a part of a string. You want