Find and replace text in a web page with javascript and arrays


HTML • JavaScript • Lotus Formula


Create the array object, then fill in individually so () are not an issue.

function packagenames() {
	for ( i=0 ; i<pkgids.length ; i++ ){
		input = "<td>" + pkgids[i] + "</td>";
		output="<td>" + pkgnames[i] + "</td>";
		document.body.innerHTML = document.body.innerHTML.replace(input,output);
	}
}

<script>
var pkgids = new Array(<ComputedValue1>);<ComputedValue2>;
var pkgnames = new Array(<ComputedValue3>);<ComputedValue4>;
packagenames();
</script>

ComputedValues 1 thru 4

REM "COMPUTED 1";
@Text(@Elements(packageids))

REM "COMPUTED 2";
ubound := @Elements(packageids);
@For(n:=1; n<=ubound; n:=n+1;
	tmp := tmp + "pkgids["+@Text(n)+"]=\"" + packageids[n] + "\";"
);
tmp

REM "COMPUTED 3";
@Text(@Elements(packageids))

REM "COMPUTED 4";
ubound := @Elements(packageids);
@For(n:=1; n<=ubound; n:=n+1;
	tmp := tmp + "pkgnames["+@Text(n)+"]=\"" + packagenames[n] + "\";"
);
tmp

Written by Frank Joseph Brefere III

Posted by fbrefere001 on Wednesday September 23, 2009