Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How To Scroll A Text Area To A Highlighted Text

Status
Not open for further replies.

shox321

Programmer
Apr 25, 2007
3
0
0
EG
hi
I Made A Code That Searches In A Text Area For A Specific Text And Highlights It (In IE The Text Area Scrolls Down Automatically To The Highlighted Text) But In FireFox It Doesn't . . How Can I Make It Scroll Down To The Selected Area My Code Is below :
** Assuming That $()=document.getElementById()
** Also Assuming That The id of the TextArea is "deisng_file_html"

function high_light(search_word){
$('design_file_html').value = $('design_file_html').value.replace(/(\r\n)*/g, "");
$('design_file_html').value = $('design_file_html').value.replace(/(\n)*/g, "");
var sel_start=$('design_file_html').value.indexOf(search_word);
if(sel_start==-1)
{
sel_start=0;
var sel_end=0;
}else{
sel_end=sel_start+search_word.length;
}
if(typeof($('design_file_html').selectionStart)=='number') {
$('design_file_html').focus();
$('design_file_html').select();
$('design_file_html').selectionStart = sel_start;
$('design_file_html').selectionEnd = sel_end;
} else if(document.selection && document.selection.createRange) {
$('design_file_html').focus();
$('design_file_html').select();
var rng2 = document.selection.createRange();
rng2.collapse();
rng2.moveStart('character',$('design_file_html').value.indexOf(search_word));
rng2.moveEnd('character',search_word.length);
rng2.select();
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top