If you're tempted to say this has been answered by the SO answer: 5117127 please don't - it doesn't help me out. That answer says I can use the window object to access it: window['varToReturn'] - this is not working.
A basic form:
<form id="formID">
<input type="number" id="inputID"/>
</form>
I have basic variables with values:
var varName1 = 1 ;
var varName2 = 2 ;
Then am using a function to get the appropriate variable name to return:
$("#formID").submit(function(e){
e.preventDefault();
var inputValue= $("#inputID").val();
var varToReturn = 'varName' + inputValue;
console.log(varToReturn);
});
It's returning 'varToReturn1' - not the variable value (which is just '1')...am sure it's probably a simple thing, but help would be appreciated.