为什么这个HTML代码只有在我用PHP回显它时才能正常工作?

I am using the Captcha made by Securimage.

When I write the following code in HTML section:

<tr>

<td><img id='captcha' src='/securimage/securimage_show.php' height='50' 
width='135' alt='CAPTCHA Image' /><br>

<a href='' onclick=\"document.getElementById('captcha').src
'/securimage/securimage_show.php?' + Math.random(); return false\">
[ Different Image ]</a></td>
<td><input type='text' name='captcha_code' size='20' maxlength='6' /></td>

<tr>

... And I click on "Different image" to change the captcha, the whole page refresh, thus losing all text entered into text fields.

But when I take all that code and put it into PHP echo statement, the captcha changes without refreshing the whole page (which is what I want)

Do you guys know why does this happen? This is really disturbing!

Thanks in advance

Try removing the backslashes from the onclick attribute. When you echo that from PHP, perhaps PHP melts them out.