Return to Snippet

Revision: 2702
at March 29, 2007 11:40 by davaodude


Initial Code
function copyDown(nm) {
// written by Daniel P 3/20/07
// repeat the values of the first row of a column down the whole column
// special case for sku: value in incremented as you go down.
// also, values are only filled in for rows that have a sku filled in
	var lastskuindex = document.getElementById('lastindex');
	var firstitem = document.getElementById(nm+'0');
	z = firstitem.value;
	for ( i=1; i<=lastskuindex.value; i++ ) {
		//window.receivelist["Received"+i].checked=true;
		if (nm=='SKUCode' && z!='') {	// special case for skucode (when not blank)
			z++;	// increments the sku
			zstring = z.toString();
			if ( zstring.length == 1 )	zstring='00000'+zstring;
			if ( zstring.length == 2 )	zstring='0000'+zstring;
			if ( zstring.length == 3 )	zstring='000'+zstring;
			if ( zstring.length == 4 )	zstring='00'+zstring;
			if ( zstring.length == 5 )	zstring='0'+zstring;
			document.getElementById(nm+i).value = zstring;
		} else {
			if (document.getElementById('SKUCode'+i)) {	// if there's an editable skucode (only add page)
				if (document.getElementById('SKUCode'+i).value != '') {	// only update this row if sku is filled in for this row
					document.getElementById(nm+i).value = firstitem.value;
				}
			} else {	// not add page, so we just update regardless of if sku is filled in
				document.getElementById(nm+i).value = firstitem.value;
			}
		}
	}	// looping down the rows
}

Initial URL

                                

Initial Description
Copy values from the first row of a column down the entire column.  This was used in a specific project, but the code could be helpful for other projects.

Initial Title
Copy/repeat input form values

Initial Tags
form

Initial Language
JavaScript