The regex is the problem here. Replace the +
with a *
for a quick fix. But you should probably just do img.src = 'image.php?name=' + this.value;
The plus looks for at least 1 character. So when you blank it out, img.src ends in name=
and no longer has [^&]+
to replace