I am currently doing this
var currentImage = $('#compImg').attr('src');
This will give me one of two URLs, which are the following
http://localhost:8000/images/folder1/Yearly/somename_Yearly_something.png
http://localhost:8000/images/folder1/Monthly/somename_Monthly_something.png
The only difference is the words Monthly and Yearly. On the page that displays the image I have a select box, with the values Monthly and Yearly. If they select something, and it is not currently being displayed, I need to switch the image. So say I land on the page and it is displying the Monthly image path. If I select Monthly from the select box, nothing should happen. If I select Yearly, it should replace the URL with the Yearly URL. I think the best way to do this is just replace the occurences of Monthly in the URL to Yearly, because the rest is the same.
At the moment I have this:
$( "#yearMonth" ).change(function() {
    var currentImage = $('#compImg').attr('src');
    if($(this).val() == 'Yearly') {
        var newImage1 = currentImage.replace("Monthly", "Yearly");
        $('#dashboardImage').attr('src', newImage1 + '.png');
    }
    if($(this).val() == 'Monthly') {
        var newImage2 = currentImage.replace("Yearly", "Monthly");
        $('#dashboardImage').attr('src', newImage2 + '.png');
    }
});
At the moment nothing seems to happen. How can I replace the word if needed?
 
     
     `
        – freedomn-m
                Jul 20 '16 at 14:37
`
        – freedomn-m
                Jul 20 '16 at 14:37
     
     
    