It doesn't work because the field elements and the ||myfield#id|| tags are available only in the Add Entery template.
You can assign an id to the img element and let the js check its src attribute and if empty assign a default value. Something like:
<div id="mydiv">
<img id="id_myImage" src="||myfield||" />
</div>
<script type="text/javascript">// <![CDATA[
var myImage = document.getElementById('id_myImage');
if (myImage.src == '') {
myImage.src = 'url-to-default-image-src';
}
// ]]></script>
