I couldn't find why this was happening but on reflection decided to do this a whole different way. I thought I would share my solution here for anyone else using WordPress.
Basically, I put the script element of the View Cart code in my header template (header.php), the rest of the View Cart code and the Add To Cart code in the post template (single.php), and then added a custom field to the post to pass the E-Junkie Item No to the button code.
It works and was far easier than I had thought it might be! I'll give the details now.
First, take the script code from the View Cart code - that's everything between the first "<script" and the final "script>" - should be about six lines. Insert it into your header template (header.php) in the <head> section - I put it just before the "<link rel=" lines.
Second, look at your Add To Cart code and find the item number - it is the number that comes straight after the "i=", mine was a six digit number. Make a note of that number. Now, go to edit your post where you want the buttons. Towards the bottom of the page you have a big block headed "Custom Fields". Create a custom field by adding a meaningful field name (I used "ej_itemno"), and add the item number you just noted in the value box. Publish the post. That itemno is now linked to the post.
Third, edit your single post template (single.php). just before or after the main content (displayed using the line starting "<?php the_content") paste your Add To Cart and View Cart button code (minus the script bit you've already put in the header). Now, where the itemno appears ("i=xxxxxx") replace that with i=<?php echo(get_post_meta($post->ID, 'ej_itemno', true)); ?> (if your custom field wasn't called ej_itemno then change that bit). This will pump your itemno from the post into the code.
You want to only show the buttons where the post has an E-Junkie itemno so surround the code you've just pasted with these lines:
<?php if ( get_post_meta($post->ID, 'ej_itemno', true) ) { ?>
<p>
</p>
<?php } ?>
Your finished code will look something like this:
<?php if ( get_post_meta($post->ID, 'ej_itemno', true) ) { ?>
<p>
<a href="https://www.e-junkie.com/ecom/gb.php?c=cart&i=<?php echo(getpost_meta($post->ID, 'ej_itemno', true)); ?>&cl=12345&ejc=2" target="ej_ejc" class="ec_ejc_thkbx" onClick="javascript:return EJEJC_lc(this);"><img src="http://www.e-junkie.com/ej/ejadd_to_cart.gif" border="0" alt="Add to Cart"/></a>
<a href="https://www.e-junkie.com/ecom/gb.php?c=cart&cl=12345&ejc=2" target="ejejc" class="ec_ejc_thkbx" onClick="javascript:return EJEJC_lc(this);"><img src="http://www.e-junkie.com/ej/ejview_cart.gif" border="0" alt="View Cart"/></a>
</p>
<?php } ?>
(remember not to just cut and paste the code above because your code will be different )
That's it! in any post, if you put an E-Junkie item no (from your item's button code) in your new custom field, the buttons will magically appear. And if you don't - they won't!
Hey, it works for me anyway!