After scouring the forums, I've been trying to use window to turn a parameter entered as a string into a workable variable. Here we start with the target location in the p tag...
<p id="rent"></p>
Then I call the function using the parameter "rent" to obtain the variable rent.
var rent = 125;
function display(attribute) {
document.getElementById(attribute).innerHTML = window.attribute;
}
display("rent");
However it still returns "undefined" so I must be making a mistake in syntax. Any solutions?
Update: @Sidd has the right approach in changing it to window[attribute] but I still can't get it to work with object properties, for example if you call rent.amt.