ma perchè vuoi usare javascript? Non è meglio usare un normale if then else lato server e stampare direttamente l'elemento img corretto?