I'm trying to create a function that will do the following:
I have some text-boxes and each of them is linked to a variable with a name like:
"textbox1"
, "textbox2"
and so on.
My function needs to change the value of a textbox
, when a (change)
event is triggered.
Depending on where the event happens, I want to change the value of a specific textbox
.
In words, my function would do this:
func foo(newVal: string, textboxNumber: number) {
this.textbox + textboxNumber = newVal;
}
so basically, construct the textbox
variable name (ie. textbox1
), and the correct number is passed as argument to the function.
I just don't know how to construct the name of the variable and make it usable!
I know I could for example use CASES, so for each different case, I would use the correct value:
SWITCH (myCase) {
case 1 : this.textbox1 = newVal;
}
but the number of textbox
is dynamic and growing, so I would like a solution like mine, where I decide in the argument of the function which textbox
is going to get updated.