Stack Exchange
Don't reset attribute after form submition
I've the code which submits the form#statisticForm. In the script I have written I substitute src, which is located inside the span element:
<form id="statisticForm">
    <input type="hidden id="statisticForm:fsp" />
    <span id = "span1" class="a-custom-sorting">
        <img src="img.jpg"/>
    </span>
    <!--Another such span elements -->
    <span id = "span123" class="a-custom-sorting">
        <img src="img.jpg"/>
    </span>
</form>

Script:
jQuery('.a-custom-sorting').click(function() {
    var submitField = document.getElementById("statisticForm:fsp");
    var img = jQuery(this).find("img");
    var new_src;
    switch (img.attr("src")) {
        case "img.jpg":
        case "second_clicked_img.jpg":
            new_src = "img1.jpg";
            break;
        case "first_clicked_img.jpg":
            new_src = "img2.jpg";
            break;
    }
    img.attr("src", new_src);
    submitField.value = this.id;
    document.getElementById("statisticForm").submit();
});

But after the form submition using the script above, src attribure of the img tag inside the span element I've clicked become equals to img.jpg. But I want that after form submission, src attribute doesn't change it value. How can it be done?

If you refresh the page after the submit, you lost your switch in .click() and the DOM reload the default attributes.
You can make form with ajax and make change at callback, or set a variable after the refresh, and set the new attribute on document ready. 
