[Javascript] Stem Joining Question

Peter-Paul Koch gassinaumasis at hotmail.com
Mon Aug 6 09:24:48 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.

>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.

document.orderforms.elements[qtyvar].value

You create strings with your variable definitions above, not variable names. 
Fill in the strings in the array (and also associative array) elements and 
you access the field, if the name contained in the string qtyvar exists.

You cannot use this Perl technique in JavaScript.

ppk

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp




More information about the Javascript mailing list