Skip to content
Advertisement

Use function parameters as a variable call

what has already been described in the title, but basically I want to send a function perimeter and use it to call one of the three different variables. Also so it doesn’t come to a miss understanding the “$(‘#’+id)” part of the code works all I need is the correct syntax for the “id =” part (if even possible). And I know there is a workaround but I am trying to minimize code and this seems like the most optimal solution.

my code:

JavaScript
JavaScript

Advertisement

Answer

ok, I think I finally understood what you’re after

so you’re passing a variable name and want to dynamically call it, instead of going the global way using this, I would recommend to do it by having all your vars in just one global one, for example

JavaScript

and then you can easily read/write them with formInputs[ var_name_here ]

so your example, would be written as

JavaScript

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement