Click to See Complete Forum and Search --> : I desperately need help on a script problem
cityelinks
09-30-2003, 06:07 PM
What do I need to do to keep a search results page from opening in a new window?? I need it to open in the current location. Here is the link to the page.
http://www.cityelinks.com/City/Asheville_NC/Local/Search.html
Use the keyword ' Games '
Please help me with this as I am a script newb. Thanks
It's there because it uses document.write() and it's a bit of work to write it to the page itself...
[J]ona
cityelinks
09-30-2003, 06:55 PM
Would I be able to write it to a new page without it going to a popup?
Would you like it to be written to the page (in HTML), or to be written inside of a textbox? Also, would you like ketchup with that? :D
[J]ona
cityelinks
09-30-2003, 07:21 PM
LOL [Jona] Yes... ketchup would be fine...:D
In just plain html would be great... How do I do that?
Well, find an object in your page that you want to put the display in. Let's assume it's a DIV with id="searchHolder"
Now let's use this code:
function search(frm) {
var sDiv = document.getElementById("searchHolder");
sDiv.appendChild(document.createTextNode(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;
}
sDiv.appendChild(document.createTextNode("</table><br>Total found: "+total+"<br></body></html>"));
}
Of course, that means that you have to have <div id="searchHolder"></div> somewhere on your base (as I already said).
[J]ona
cityelinks
09-30-2003, 08:12 PM
[J]ona I pasted the new code and added the div tags. Although I am not quite sure how this particular tag is used. When I ran the search, I got an "sDiv is undefined" error. Where are you defining that function?
Would this be easier if it created a new page to display the search results? I think this would be the best way.
BTW thanks for the help. I really appreciate it.
Replace my function with the one that was already on your page, and make sure you have the DIV exactly as I specified.
[J]ona
cityelinks
09-30-2003, 08:27 PM
I copied and pasted the function and the tag to the page. Does the div tag need to be enclosing anything in particular? I currently have it at the bottom of the page after the landscape image.
I will update the website so you can take a look.
Ah, my mistake. I forgot something, lol. Let me go back and edit my other post...
[J]ona
cityelinks
09-30-2003, 08:38 PM
[J]ona...
Ok got it pasted. However, it is now giving me a 'win not defined' error... Would it be 'show(w, frm , n);' instead of show'(w, win, n);' ? It is very close. Could it display the results on a blank page?
function search(frm) {
sDiv = document.getElementById("searchHolder");
sDiv.appendChild(document.createTextNode(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, n);
fnd[w] = 0;
}
sDiv.appendChild(document.createTextNode("</table><br>Total found: "+total+"<br></body></html>"));
}
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>";
document.getElementById("searchHolder").appendChild(document.createTextNode(line));
return 1;
}
[J]ona
cityelinks
10-01-2003, 11:42 AM
[J]ona... Thanks!!! That did it. You are the best. 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
You can add http://www.ComputerMasterMinds.tk/ for me. :) I'm glad I've helped you, and you can call me Jona.
[J]ona