...

View Full Version : refer from within div to window in different div



yosibeck
08-03-2008, 01:29 AM
sorry folks, I'm sure this is a newbie question.
On my website I have one DIV (id="menu") with position:fixed that serves as a fixed menu bar.
Then comes the second DIV (id="content") that holds the whole content of the site (genealogy reports rendered by PHP from SQL).
I want to put a Javascript searchbox in the menu, that searches in the content window.
The present Javascript in the HEAD section of the page says:

<script language="JavaScript">
var NS4 = (document.layers);
var IE4 = (document.all);
var win = window;
var n = 0;
function findInPage(str) {
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("Not found."); }
if (IE4) { txt = win.document.body.createTextRange();
for (i = 0; i <= n && (found = txt.findText(str)) != false; i++)
{ txt.moveStart("character", 1); txt.moveEnd("textedit"); }
if (found) {
txt.moveStart("character", -1); txt.findText(str); txt.select(); txt.scrollIntoView(); n++; }
else { if (n > 0) { n = 0; findInPage(str); }
else alert("Not found."); } } return false; } </script>

The short code for the box itself that of cause goes into the BODY section:

<form name="search" onSubmit="return findInPage(this.string.value);">
<div align="center">
<p><font size=3> <input name="string" type="text" size=15 onChange="n = 0;"> </font>
<input type="submit" value="Search Page"> </p> </div>
</form>
Problem is that this way the search is made within the DIV in which the searchbox code is placed. So when I put the code for the search box in the id=menu DIV, it searches in the menu bar itself.
I can't put it in the content part (which would make it search there) because then the box scrolls out of sight on the long pages, so you can't make further searches for the string...

How do I change the Javascript in the HEAD section so that though I place the search box in the menu DIV, it will search in the content DIV.
I understand that the change has to be made to the

var win = window
part, to make it refer to the other DIV, but I don't know how to change that.
Would greatly appreciate your help.
Yossi

ypelleg
08-03-2008, 08:55 PM
I got a similar problem. Tried several forums, but no luck so far...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum