I have a Javascript code snippet below where the image name "samson decosta" is stored in a MySQL database. I am retrieving this image and trying to display it as a background_image in a div.
document.getElementById("image_chk").style.backgroundImage="url(img/"+ clicked_id+".jpg)";
The issue I am facing is that whenever I store an image name with spaces between the words, the image does not display. However, when I replace the spaces with underscores (or remove spaces altogether), the image displays correctly.
For example,
clicked_id = samson decosta (unable to retrieve this image due to spaces).
clicked_id = samson_decosta (able to retrieve this image).
clicked_id = samsondecosta (able to retrieve this image).