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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry Could someone pleasepleaseplease check what's wrong with this code?

    I don't know much about javascript and i'm trying to let a site search script open the results on the page "search_results.php" in the frame "searchresults" but it won't work and i'm freaking out right now.

    the javascript code:
    Code:
    var item = new Array();
    
    // "Page Name","path","Page Title","Many,Key,Words","Descriptive Comments"
    
    c=0; item[c]=new Array("example.php","","title","keywords","description");
    c++; item[c]=new Array("example.php","","title","keywords","description");
    
    page="<html><head><title>Search Results</title></head><center><span><b><h1><font color=\"\#303030\" face=\"verdana\"> Search Results</font></h1></b></span><table border=0 cellspacing=10 width=80%>";
    
    
    function search(frm) {
    win = window.open("search_results.php","searchresults","","");
    win.document.write(page);
    txt = frm.srchval.value.split(" ");
    fnd = new Array(); total=0;
    for (i = 0; i < item.length; i++) {
    fnd[i] = 0; order = new Array(0, 4, 2, 3);
    for (j = 0; j < order.length; j++)
    for (k = 0; k < txt.length; k++)
    if (item[i][order[j]].toLowerCase().indexOf(txt[k]) > -1 && txt[k] != "")
    fnd[i] += (j+1);
    }
    for (i = 0; i < fnd.length; i++) {
    n = 0; w = -1;
    for (j = 0;j < fnd.length; j++)
    if (fnd[j] > n) { n = fnd[j]; w = j; };
    if (w > -1) total += show(w, win, n);
    fnd[w] = 0;
    }
    win.document.write("</table><br><font color=\"\#202020\" face=\"verdana\">Total found: "+total+"</font><br></body></html>");
    win.document.close();
    }
    function show(which,wind,num) {
    link = item[which][1] + item[which][0]; 
    line = "<tr><td><a href='"+link+"' target=\"\_parent\"><font size=\"4\"color=\"\#0B615E\" face=\"verdana\">"+item[which][2]+"</a><br><font size=\"4\"color=\"\#303030\" face=\"verdana\">";
    line += item[which][4]+ "</font></td></tr>";
    wind.document.write(line);
    return 1;
    }
    on the page called "search_results.php" ive got a frame called "searchresults"
    but when I search, the result open in a new tab with "about:blank" as url and without the other content of search_results.php on it. could someone plzplzplz check my code for me and say what i've done wrong?

  • #2
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    win = window.open("search_results.php","searchresults","",""); // this means opena new window with the following url. ( bear in mind you are not providing and search value from which to obtain your results)
    win.document.write(page); // this mean rewrite the entire page I jsut opened with the new html

    You are overwriting your results page.

  • #3
    New to the CF scene
    Join Date
    Jun 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Then how can I let the results open in a frame in a page?


  •  

    Tags for this Thread

    Posting Permissions

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