I’m printing some values inside my HTML page where a textarea carries values that are String.raw. For example:
<script>
var ENV = String.raw`
{
"id": "15bbb91c-b9d9-4238-8eb5-01c991d613ba",
"name": ""${ENV_NAME_VARIABLE}"
}
`;
document.write(`
<textarea id="envid" >` + ENV + ` </textarea>
`
);
</script>
This textarea shows up properly. Now through some interactivity in the page, let’s say a button, I want to change the value of this ENV_NAME_VARIABLE
, and I’d like to show that in the textarea in the page. How could I retrieve the current value inside this bit, and replace with a new value?
<script>
let ENV_NAME_VARIABLE = 'TESTING NAME';
var ENV = String.raw`
{
"id": "15bbb91c-b9d9-4238-8eb5-01c991d613ba",
"name": "${ENV_NAME_VARIABLE}""
}
`;
document.write(`
<textarea id="ENV" style="width: 80%; height: 100">` + ENV + ` </textarea>
`
);
function updateName() {
original_text = document.getElementById('ENV').value;
//////------ HERE I WANT TO GET THE value of ENV_NAME_VARIABLE.....
/////--------- AND REPLACE THAT to ABC
}
</script>
<p>
<button onclick="updateName(); ">Change value of name to ABC</button>