tags:

views:

126

answers:

2

I need to put a javascript variable as image source. That is my image tag should be in this format here i am adding my script

document.getElementById("pricefilter").innerHTML ='<img src="variablename/spinner.gif" title="Loading..." alt="Loading...">';

The variablename carries my image path. How can I put this in double quates.

Please help to solve this

+2  A: 

If i get your question correctly use

document.getElementById("pricefilter").src=ur variable;

One of previuos stackoverflow ques similar to urs showed this

<img src="blank.png" id="image" alt="just nothing">
<script type="text/javascript">
    document.getElementById('image').src = "yourpicture.png";
</script>
Pandiya Chendur
+2  A: 

Strings can be added together, if variablename contains the path:

document.getElementById("pricefilter").innerHTML ='<img src="' + variablename +
  '/spinner.gif" title="Loading..." alt="Loading...">';
gnarf