Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
193
rated 0 times [  199] [ 6]  / answers: 1 / hits: 20105  / 10 Years ago, wed, august 6, 2014, 12:00:00

Given textarea is a textarea element with id 'textareabox', how can I check if it contains a string within it?



var textarea = document.getElementById('textareabox');

var word = something;

if (!textarea.contains(word))
{
textarea.value += word;
}

More From » javascript

 Answers
12

You can use .value, as:



var textarea = document.getElementById('textareabox');

var word = 'something';

var textValue=textarea.value; //-> don't use .innerHTML since there is no HTML in a textarea element

if (textValue.indexOf(word)!=-1)
{
alert('found')
}

[#69881] Tuesday, August 5, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
loganl

Total Points: 424
Total Questions: 86
Total Answers: 112

Location: Zimbabwe
Member since Thu, Jul 21, 2022
2 Years ago
;