Click to See Complete Forum and Search --> : Opening search results in same page...?


cityelinks
09-29-2003, 07:01 PM
I am a javascript beginner and having a problem with a script. I need the search results page to open in the the current frame and window. currently, the script pops up a new window. I have tried several things, but to no avail. I know the script that needs to be changed is in the following

function search(frm) {
win = window.open("","","scrollbars");
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);
}

I am pretty sure it has something to do with the second line. but I can't keep it from opening a new window. Can someone help me with this please? :confused:

Al

Sam
09-29-2003, 09:27 PM
delete the second line and replace win in the third line with the name of your frame

cityelinks
09-29-2003, 09:54 PM
samij586: Ok, did that. but got a script error. I then completly removed the 'win' from the third line. The page begins to load in the correct page, but nothing is displayed. I then get an 'srchval.value not an object' error.
What am I doing wrong here? This is what I have now:

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var item = new Array();

// "Page Name","path","Page Title","Many,Key,Words","Descriptive Comments"

c=0; item[c]=new Array("consignment.html","../Listings/","Home Furnishings","consignment,storehouse,furniture,haywood,home,furnishings,dishes,sofas,couch,chair,chest,artwork,dol ls,lamps,mirrors,antiques,vintage,crystal,desks,dining,bedroom,collectables,asheville,tables,barstoo ls","The Storehouse - Used furniture and consignments. 864 Haywood Rd., Asheville (828) 254-5865");

page="<html><head><title>Search Results</title></head><body bgcolor='white'><table border=0 cellspacing=2 width=80%>";


function search(frm) {
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;
}
document.write("</table><br>Total found: "+total+"<br></body></html>");
document.close();
}
function show(which,wind,num) {
link = item[which][1] + item[which][0];
line = "<tr><td><a href='"+link+"'>"+item[which][2]+"</a> Score: "+num+"<br>";
line += item[which][4] + "<br>"+link+"</td></tr>";
wind.document.write(line);
return 1;
}
// End -->
</SCRIPT>