[Javascript] Stem Joining Question

Rees, Mark (TWIi London) mrees at twii.net
Mon Aug 6 09:34:24 CDT 2001


Hello

List seems very slow today - my last post took 5 hours to come up.

for 
var qtyvar = "qty"+rownum;

try 
var qtyvar = eval("qty"+rownum);

or save yourself writing out a long string and maybe:

qtyvar=eval(document.orderform.qty' + rownum + '.value');

Hope this helps

Mark

-----Original Message-----
From: Roland Corbet [mailto:Roland at psyche.net.uk]
Sent: 06 August 2001 14:24
To: javascript at LaTech.edu
Subject: [Javascript] Stem Joining Question


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

_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
http://www.LaTech.edu/mailman/listinfo/javascript



More information about the Javascript mailing list