I am developing a flask app. I have a flask form and I am trying to color only part of an input field. The idea is that I would get two indices that will represent the start and end of the substring in an input field that I need to color.
My code is as follows:
The inputField
:
review = TextAreaField('Review', validators=[DataRequired()])
The HTML:
<p>
{{ form.prompt.label }}<br>
{{ form.prompt(size=32) }}
</p>
Using Chrome's inspector (Ctrl + Shift + I):
<p>
<label for="review">Review</label><br>
<textarea id="review" name="review" required="" size="32">This is a test case</textarea>
</p>
The JavaScript function:
<script>
var label = document.getElementById('review');
var sub = label.innerHTML;
label.innerHTML = label.innerHTML.replace(sub.substring(0,2), '<span style="color:red;">'+sub.substring(0,2) '+'</span>');
</script>
This function however does not style the text. It instead fills the text box with
"<span style="color:red;">'+sub.substring(0,2) '+'</span>".
What would be a good way to resolve this issue?