Click to See Complete Forum and Search --> : document.write question


cityelinks
09-30-2003, 03:01 PM
I am a javascript beginner and having a problem with a script. I need the search results page to open in the current page. Currently, the script pops up a new window. I have tried several things, but to no avail.


<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/","The Storehouse","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","Home Furnishings > Furniture-used - Used furniture and consignments.");

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

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);
}
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>Total found: "+total+"<br></body></html>");
win.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>


I am pretty sure it has something to do with the 'win = window.open' line. I have removed the 'win' part of the lines, but I can't keep it from opening a new window. Can someone help me with this please? :confused:

Al

Khalid Ali
10-01-2003, 09:13 AM
Originally posted by cityelinks
....I have tried several things, but to no avail.
Al

apparently not...;)

here is the solution

<script type="text/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/","The Storehouse",
"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","Home Furnishings > Furniture-used - Used furniture and consignments.");

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

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);
}
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,consignment n);
fnd[w] = 0;
}
document.write(page+"</table><br>Total found: "+total+"<br></body></html>");
//win.document.close();
}
function show(which,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);
page+=line;
return 1;
}
// End -->
</SCRIPT>

cityelinks
10-01-2003, 11:44 AM
Khalid Ali; Thanks!!! That did it. You are awesome. I have a quick links page on my site If you have a site you would like me to link to, I would be happy to add it. Emai me and let me know... Thanks again. -Al