title: How to refresh captcha code without refreshing the page
body: <p>When I click on my given refresh link, my captcha code refreshes only once. If I again click on the refresh link it doesn't refresh the captcha code. I don't understand why that is happening. </p>
  
  <p>This is my code:</p>
  
  <pre><code>&lt;a href='javascript: refresh_captcha();'&gt;refresh&lt;/a&gt;  
  function refresh_captcha()
  {
      &lt;?php
          $captcha1 = new CaptchaCode();
          $code = str_encrypt($captcha1-&gt;generateCode(6));
  
      ?&gt;
      var img = document.getElementById('captcha_img');
      img.src = '&lt;?php echo "/captcha_images.php?width=120&amp;height=40&amp;code=$code"?&gt;';
      document.getElementById ("captcha_img").src = img.src;
  
  }
  </code></pre>