Bug in js using temp.join, to be corrected

Hi JavaScript Gurus,

I have a problem due to a bug found in a js used by a Joomla component (Alberghi), now virtually abandoned.

unfortunately, this component is the main one in a site I made time ago for a Tour Operator, with some workaround I created to better satisfy the specific needs of a Tour Operator, managing tour-packets, vs. a simple Hotel.

this is the code:

<script language="JavaScript">
	var folderimages = new Array;
	<?php	$i = 0;
	foreach ($images as $k=>$items) {
		foreach ($items as $v) {
			echo "\
	folderimages[".$i++."] = new Array( '$k','$v->value','$v->text' );";
		}
	}
	?>
	function updateImageField ()
	{
		var temp = new Array;
		for (var i=0, n=document.adminForm.imagelist.options.length; i < n; i++) {
			temp[i] = document.adminForm.imagelist.options[i].value;
		}
		document.adminForm.images.value = temp.join( '\
' );
	}
</script>

this code works in a js-tabbed admin page with an option list showing a list of available images uploaded on the server, from where is possible to select some files to load on a second option list: once on the second list the images, by saving the page, are loaded into the relevant db table-row field.

I guess the developers didn’t test the script in a running site, as the problem was not found at the beginning, with the first creation of the packet items: the problem arises when editing/updating an existing packet provided of an existing image list.

at each further saving, the image list is modified by adding a new blank row, thus creating a mess on the output page, where the blank rows are read as missing images, showing the <alt=“click to zoom”, instead of a regular column of thumbnails.

I found that the problem is given by the code temp.join( ’
’ )
, so I changed it in temp.join( ’ ’ ): the existing file lists are no more filled in by blank rows, but is not possible to get a proper list with a new packet, as the image names are not placed in a stacked list (no way to see them, later, in the newly generated page).

my so poor knowledge of JavaScrpt prevents me to find out a workaround (I know just a little PHP) either to make the script sensitive to an existing file list, without the blank row insertion, or to find out a wiser way to create one-shot only new rows.

thanks in advance for any hint or suggestion that could help me in solving this embarrassing flaw of the original script.