[Javascript] Stem Joining Question

Roland Corbet Roland at psyche.net.uk
Mon Aug 6 08:24:17 CDT 2001


I program mainly in Perl, but dabble occasionally in JavaScript.  In Perl,
the ability to make variable names "on the fly", so to speak is a great
function.

For example.

$RowNum = 1;
$STEM = "Row$RowNum"

I can then use $$STEM, which is the same as accessing $Row1. - I've made the
variable name up while working through the code.

I have to write a JavaScript form that will add up rows and then columns.  I
was wondering if this sort of methodology is possible within JavaScript.
(Instead of writing out all of the calculations in full).  I have tried the
following, but without any luck.

onchange="CalcRow(1)";

function CalcRow(rownum) {
	var unitvar = "unit"+rownum;
	var qtyvar = "qty"+rownum;
	var totalvar = "total"+rownum;

	alert(unitvar);
	alert(qtyvar);

	alert(document.orderform.qty1.value); //This alerts OK.
	alert(document.orderform.qtyvar.value);  //No alert on this one.

	if ((document.orderform.unitvar.value != "") &&
(document.orderform.qtyvar.value != "")) {
		document.orderform.totalvar.value = document.orderform.unitvar.value *
document.orderform.qtyvar.value;
	}
	else {

	}
}

If anyone could point me in the direction of how to create and access new
variables in this method, I would really appreciate it.

TIA for your time and help.

Kind regards,

Roland
--
Roland Corbet
Systems Administrator & Developer
Psyche Solutions Limited
Chester Road
Cradley Heath
West Midlands
B64 6AB

Tel:    + 44 (0)1384 414183 Ext. 4412
Fax:    + 44 (0)1384 414141
Email:  Roland at psyche.net.uk
WWW:    http://www.psyche.net.uk




More information about the Javascript mailing list