Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question refer from within div to window in different div

    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:
    Code:
    <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:
    Code:
    <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
    Code:
    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

  • #2
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I got a similar problem. Tried several forums, but no luck so far...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •