Dave_Williams Dave_Williams - 1 month ago 7
Javascript Question

How to change character in textarea value?

So, say I have a textarea.

<textarea id="area">Test text</textarea>


How can I search for a specific string (For example, "text") and remove it?

I tried this, but to no avail.

document.getElementById("area").replace('text', '');


Any and all help is appreciated!

Answer

Simple and easy JavaScript fix:

var area = document.getElementById("area");
area.value = area.value.replace('search', 'string');

This should work with your original TextArea:

<textarea id="area">Test text</textarea>