I am making a program to search for characters in the desired <textarea>
. I need to color the specific character that i found in text area. How can I color the character(s) in the <textarea>
? For example, if i enter 'a' in input field than all the 'a's in the <textarea>
should colored red.....
HTML
<form method="post" name="searching" onSubmit="return check(this)">
<table border="0" cellpadding="10px" align="center">
<tr><td width="114">
<label><b>Text</b></label></td>
<td width="287">
<textarea name="para" cols="30" rows="10"></textarea>
</td>
</tr>
<tr>
<td>
<label><b>Alphabet</b></label>
</td>
<td><input type="text" name="character" title="Enter Character">
</tr>
<tr>
<td colspan="2" align="center">
<input id="btn" type="submit" name="submit" value="Search">
</td>
</tr>
</table>
</form>
JS
<script language="javascript">
function check(form)
{
if(form.para.value==""){
alert("No text is available for search!!");
return false;
}
if(form.character.value=="")
{
alert("Search keyword is not Enter!!");
return false;
}
para=new Array();
index=new Array();
keyword=form.character.value;
para=form.para.value;
found=0;
k=0;
for(i=0; i<para.length;i++)
{
if(keyword==para[i]){
found+=1;
$(document).ready(function(e) {
$("textarea:eq(i)").css("color","#FF0000");
});
index[k++]=i;
}
}
if(found!=0){
alert(found+" times "+keyword+" in text");
alert("Index of alphabet: "+index);
return false;
}
else{
alert("Not found in the Text!!");
return false;
}
}
</script>
I'm looking for any solution, be it in CSS, HTML, JS (or jQuery). Thanks.