Highlighting the selected text in textbox

Posted by Arun.Padmanaban under ASP.NET on 3/20/2012 | Points: 10 | Views : 1402 | Status : [Member] | Replies : 1
Hi, i have two textbox and one button. (1st textbox contain the default text value "finding the text", in second textbox enter the text as "the" and click on button.The text "the" in first textbox should highlight with gray color.) i need the code using javascript or jquery.




Responses

Posted by: Rajni.Shekhar on: 3/21/2012 [Member] Bronze | Points: 25

Up
0
Down
Following method will change color of TextBox1 if text of TextBox2 found in TextBox1, i am trying to color perticular found text in textBox1......

function GetValue() {
var txtPhrase = document.getElementById("TextBox1").value; //for textbox1
var txtWordToFind = document.getElementById("TextBox2").value; // for textbox2

if (txtPhrase != "") {
var arrWords = txtPhrase.split(" ");
var iIndex = 0;
for (iIndex = 0; iIndex < arrWords.length; iIndex++) {
if (arrWords[iIndex] == txtWordToFind)
{
document.getElementById("TextBox1").style.color = 'gray';
}
}
}
}

Thanks,
Rajni Shekhar

Arun.Padmanaban, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response