Show/hide images when a form is submitted.

I’ve not had any luck with calling up the function. I’ve only had it working with a second press of the submit button and I can’t figure out why. If anyone has any pointers it would be greatly appreciated