Reputation: 2074
I want to use a function's variable value to build a variable in the function.
Here's what I got so far:
function foo(1a, 1b) {
var money = document.myform.1b;
}
So basically, if I pass in foo(aaa, bbb)
, I would like the variable money to be:
var money = document.myform.bbb;
Upvotes: 0
Views: 107
Reputation: 18258
You can use document.myform[bbb]
if bbb is a string.
Which effect are you after?
1
var bbb="variablename";
var money = document.myform.bbb
or 2
var bbb="variablename";
var money=document.myform.variablename
Upvotes: 2
Reputation: 16087
function foo(a, b) {
var money = document.myform[b];
}
Also, I don't believe js vars can begin with a number.
Upvotes: 1
Reputation: 9193
var money = document.getElementById(1b);
http://www.javascript-coder.com/javascript-form/getelementbyid-form.htm
Upvotes: -1