Hi to all,
I am new to java script.I want to highlight the search terms in text area.I want to do this by using regular expression.When eve i give the value to regular expression directly it works well.But if i give it frim variable it doesn't work well.My code is below.
function add(id) {
var i=0;
id = "#"+id.replace(/:/g, "\\:");
var s="fox";
var searchText='fox';
var re = new RegExp(searchText,"g");
jQuery(id).caret(re);
}
The above not works well. If i use /fox/g instead of re it works well.
<textarea id="Text" cols="30" rows="10">
The brown 'fox'121s is jumping 1 over the brown tree fox121s is a cruel animal
</textarea>
<input class="highlight3" id="searchID" type="button" value="highlight fox" onclick="add('form:Text')"/>
What is the reason for this?How can i achieve this.
Please help me.