I may be wrong but O think you're going about it the wrong way...
right now, you have an HTML IMG tag as follows:
<img name="myImg" src="javascript:document.myImg.src='assets/' + variable + '/imagename.gif'">
I don't think you can use variables in a straight HTML document. In order to make this work, you'd have to write your page in some other scripting language like PERL, PHP, etc. Then, I think you'd have more luck by declaring the SRC value as a variable and calling the IMG tag like this:
<img name="myImg" src=variable> where variable is "assets/<something>/imagename.gif".
As another thought, you might also try something like this:
<img name="myImg" src="javascript:imgSource()"> where the SRC value is a javascript function and the function where the fnction determines the SRC value, or the SRC value is passed to the function: <img name="myImg" src="javascript:imgSource(A)">.
I haven't tried either of these but I think this will put you on the right track.
There's always a better way. The fun is trying to find it!