Image through Script, How to add variable to URL

Posted by Liso22 on Stack Overflow See other posts from Stack Overflow or by Liso22
Published on 2010-12-25T23:50:02Z Indexed on 2010/12/25 23:54 UTC
Read the original article Hit count: 319

Filed under:

I'm sure it's pretty straightforward since someone just solved a similar problem I had. I have a folder full of city images and need users to see the image corresponding to their city.

Right now I'm getting the users location without problem using "geoip_city()" but I don't quite know how to integrate it into the URL of the image. All images have the following format: New York.jpg, Boston.jpg so I just need to make the script put the location before .jpg

This is what I'm trying now:

<img src="blank.png" id="image" >

<script type="text/javascript">
    document.getElementById('image').src = "Imagenes/grupos/' + geoip_city() + '.jpg";
</script>

I believe I'm just messing with the quotes or something similar. Could anyone tell me what I'm doing wrong? Also this is where I'm testing it: http://chusmix.com/?page_id=1770

Thanks

© Stack Overflow or respective owner

Related posts about JavaScript