This is a simple example to help with a larger project -
Desired outcome: When you type a name in the form box, a sentence appears with the name included. However, only the name should have the color red, and only in the result (it shouldn't be red when it appears in the form box).
I get an error when I include "nameHere.style.color" in this code:
JS:
function getResponse(){
var nameHere = document.getElementById("name").value;
nameHere.style.color = "red";
var resultValue = "Hello my name is " + nameHere + ", nice to meet you.";
document.getElementById("result").innerHTML = resultValue;
}
HTML:
<div class="formclass">
<label for="name">Input name here</label>
<input id="name" onchange="getResponse()"></input>
</div>
<div id="result"></div>
Is there any real way to do what I'm trying to do within JavaScript?
Edit: to emphasize, I really do want to change the color of the variable that takes the element.value - not just the element. And I want it to appear in the result as the color. I can't find anything that allows me to do this correctly.