Change your img
tag to this:
<img id="badge" src="$cms_url/imaging/badge.php?badge=$mygroup['badge']; ?>">/imaging/badge.php?badge=<?php echo $mygroup['badge']; ?>" />
Then you can use below code to change your image source on click of a button, anchor or whatever:
document.getElementById("badge").src="new image src here";
You can use jQuery as well:
$("#badge").attr("src", "new image src here");