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!

scrollIntoView() with DIVs

Status
Not open for further replies.

sbushway

Programmer
Jan 27, 2003
58
0
0
US
Hi,
I read that scrollIntoView() was supposed to make the word you're searching for appear either at the top or bottom of the window (or DIV, in my case), depending on if you passed 'true' or 'false' to scrollIntoView().

My problem is that the word I'm searching for is always at the bottom of the DIV, regardless of what parameter I have in scrollIntoView().

Any ideas on how I can get the word I'm search for to appear at the top of the DIV?

Thanks in advance!
 
can you provide the code so we can see what exactly you are asking...

www.keteracel.com
banner-small.png
 
Adam,

Ideally I want just the 'save' link without the image displayed but obviously feeding the path so that when the user clicks save, the prompt pops up. I'm not sure you can achieve this with javascript alone.
 
Sure ...

These are my two JavaScript functions that I'm using:

function goto(astr)
{
var NS4 = (document.layers);
var IE4 = (document.all);
var win = this;
var n = 0;
str = astr;
var txt, i, found;
if (str == "")
return false;
if (NS4) {
if (!win.find(str))
while(win.find(str, false, true))
n++;
else
n++;
if (n == 0)
alert(str + " was not found on this page.");
}
if (IE4) {
txt = win.document.body.createTextRange();
for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {
txt.moveStart(&quot;character&quot;, 1);
txt.moveEnd(&quot;textedit&quot;);
}
if (found) {
txt.moveStart(&quot;character&quot;, -1);
txt.findText(str);
//txt.select();
progress.prate.focus();
progress.prate.select();
txt.scrollIntoView();
n++;
//search.string.focus();
//search.string.value = str;
}
else {
if (n > 0) {
n = 0;
findInPage(str);
}
}
}
return false;
}

<!-- Original: Mike Hall (MHall75819@aol.com) -->
<!-- Web Site: -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! -->

<!-- Begin
var NS4 = (document.layers);
var IE4 = (document.all);

var win = this;
var n = 0;

function findInPage()
{
str = search.string.value;
var txt, i, found;
if (str == &quot;&quot;)
return false;
if (NS4) {
if (!win.find(str))
while(win.find(str, false, true))
n++;
else
n++;
if (n == 0)
alert(str + &quot; was not found on this page.&quot;);
}
if (IE4) {
txt = win.document.body.createTextRange();
for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {
txt.moveStart(&quot;character&quot;, 1);
txt.moveEnd(&quot;textedit&quot;);
}
if (found) {
txt.moveStart(&quot;character&quot;, -1);
txt.findText(str);
txt.select();
//document.all.str.scrollIntoView();
txt.scrollIntoView();
n++;
//search.string.focus();
//search.string.value = str;
}
else {
if (n > 0) {
n = 0;
findInPage(str);
}
else
alert(str + &quot; was not found on this page.&quot;);
}
}
return false;
}
// End -->
***************************************************

myTest.cfm contains a DIV that has a list of hyperlinked codes (the links link back to myTest.cfm). When the user clicks on a code, that code is passed as a URL variable, and the page (myTest.cfm) is refreshed. The JS function goto() is called during <body onload()> and it takes that URL variable as its one parameter. The functions find that code (the URL var) in the DIV, and jump to that position in the DIV.

I want to know if there's a way to have the found code be at the top of the DIV (not the top of the list, just the top of the viewable part of the DIV)

Thank you!
 
Hi,
One more thing: I've tried to use the ScrollIntoView parameter that can be either set to 'true' or 'false', depending on if you want the object to be visible at the top of the window or at the bottom of the window.

If anyone has any ideas, please let me know.

Thank you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top