The function must be called through a link or button. For calling it through a link
For calling the same through a button
<input type="button" value="Reload Image" onclick="reloadImg()" />
Try a live demo with a captcha image.