Webspace & Domain Names This is a discussion on, Javascript help within the Freedom2Surf forum; Can anyone assist with a javascript problem i have??I'm adding a simple search function to a website, i've got the ...

Reply
 
LinkBack Thread Tools
Old 09-04-2008, 12:55 PM   #1
Tiscali User Member
 
Join Date: Apr 2005
Posts: 188
Thanks: 0
Thanked 0 Times in 0 Posts
Javascript help

Can anyone assist with a javascript problem i have??I'm adding a simple search function to a website, i've got the code working but ideally i want the search result to open up full screen-no problem getting that but then i need a hyperlink in said search window to return them back to the previous page. Code is below :-

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

/* Here is where all the magic happens.
Just enter as many additional pages that
that you want to search, then fill in the
additional listings for each page.
*/

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

c=0; item[c]=new Array("http://testdomain.html","","BT Plug (Pack of 5) 4 Way","BT,bt,plug,4 way,431,431a,","BT plug 4 way pack of 5.");
c++; item[c]=new Array("main.htm","main/","Main Page","content,main,focus","The main part of my site which contains what you have come to see. Lots of stuff like that and more great things. All in a sub directory.");
c++; item[c]=new Array("3com.jpg","images/","testing","link,image,logo,graphic" ,"The logo.jpg is just a small image which you can place on your site as a link to me. It's in a second level subdirectory.");

page="<html><head><title>Search Results</title></head><body bgcolor='white'><center><table border=1 cellspacing=10 width=250%>";


function search(frm) {
win = window.open("","","resizable, height=600");
win.document.write(page);
txt = frm.srchval.value.split(" ");
fnd = new Array(); total=0;
for (i = 0; i < item.length; i++) {
fnd = 0; order = new Array(0, 4, 2, 3);
for (j = 0; j < order.length; j++)
for (k = 0; k < txt.length; k++)
if (item[order[j]].toLowerCase().indexOf(txt[k]) > -1 && txt[k] != "")
fnd += (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;
}
test
// End -->
</script>

And the code for the search box:-


form method=get action="javascript:void(0)" onSubmit="search(this); return false;">
<input type=text name=srchval value="" size="10"><input type=submit value="Search">
</form>
<!-- Script Size: 3.16 KB -->
drgl is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript help drgl General Computing and Internet 7 24-05-2006 12:45 PM
Netgear FVS318 Vulnerabilities mikeuk General Computing and Internet 1 21-01-2005 03:30 PM
Javascript (i think!) kingjon General Computing and Internet 7 04-02-2004 08:38 PM


All times are GMT. The time now is 05:27 PM.