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

    JavaScript powered search script - results targeting.

    Hello.

    I have been working on a Javascript powered search engine for a set of browser based user guides. I can't use any server-side languages as it will all be accessed from a network drive, which as been a real pain as I would rather have just made a php search engine, but whatever...

    I have a working JavaScript search function, currently the results are displayed in the same window/frame as the search form.

    All i need is to be able to target the results to a different frame. For example, I'll keep the search form in a top frame, and some information in the bottom frame. Submitting the search form will display the results in the bottom frame. Its giving me a headache, I'm sure it is remarkably simple...

    The code:

    Code:
    title = new Object();
    desc = new Object();
    links= new Object();
    matched= new Object();
    keywords= new Object();
    found= new Object();
    var temp=0;
    
    // # of titles present in the database
    title[0]=1
    
    //no of keywords after parsing
    keywords[0]=0
    
    //no of  matches found.
    found[0]=0
    
    
    
    // SEARCH TERMS...
    
    title[1]="keywordss"
    desc[1]="title"
    links[1]="link"
    matched[1]=0
    
    
    
    
    
    
    
    
    
    
    
    
    
    function search()
    
    {
    var skeyword=document.searchengine.keywords.value.toLowerCase();
    var check=1;
    var pos=0;
    var i=0;
    var j=0;
    var  itemp=0;
    var config='';
    
    
    
    while (true)
    	{
    	if (skeyword.indexOf(" ") == -1 )
    		{
    		keywords[check]=skeyword;
    		break;
    		}
    	pos=skeyword.indexOf(" ");
    	if (skeyword !=" ")	
    	{
    	keywords[check]=skeyword.substring(0,pos);
    	check++;
    	}
    	else
    	{
    	check--;
    	break;
    	}
    	skeyword=skeyword.substring(pos+1, skeyword.length);	
    	if (skeyword.length ==0)
    		{
    		check--;
    		break;
    		}
    			 
    	}
    // the keywords have been put in keywords object.
    keywords[0]=check;
    
    // matching and storing the matches in matched
    for ( i=1; i<=keywords[0];i++)
    	{
    	for (j=1;j<=title[0];j++)
    		{
    		if (title[j].toLowerCase().indexOf(keywords[i]) > -1 )
    			{
    			  matched[j]++;
    			}
    		}	
    	}
    // putting all the indexes of the matched records  in found
    
    for (i=1;i<=title[0];i++)
    {
    	if (matched[i] > 0 )
    		{
    		  found[0]++;
    		// increment the found 	
    		  found[found[0]]=i;
    			
    		}	
    }
    
    
    
    for (i=1;i<=found[0]-1;i++)
    	{
    	for(j=i+1;j<=found[0];j++)
    		{
    		if ( matched[found[i]]< matched[found[j]] )
    			{
    			temp= found[j];
    			found[j]=found[i];
    			found[i]=temp;
    			}
    		}
    	}
    
    // end of sort
    
    output = self;
    output.document.write('<html>');
    output.document.write('<head>');
    output.document.write('<link rel=stylesheet href=style.css type=text/css>');
    output.document.write('<script>');
    output.document.write('window.onerror=new Function("return true")');
    output.document.write('</script>');
    output.document.write('<title>search results</title>');
    output.document.write('</head>');
    output.document.write('<BODY>');
    output.document.write('<a name=top>');
    output.document.write('<center>');
    output.document.write('<table width=550>');
    output.document.write('<tr>');
    output.document.write('<td class=layout>');
    output.document.write('&nbsp;<p />');
    output.document.write('<center>');
    output.document.write('<h1>search results</h1>');
    output.document.write('</center>');
    
    
    
    
      
    
    
    if (found[0]==0)
    	{
    	output.document.write('<p />');
    	output.document.write("<h2>No documents matched your search.</h2>");
    	}
    else
    	{
    	// data has been found
    	output.document.write('<p />');
    	output.document.write('<h2>');
    	output.document.write(found[0] + ' documents found...');
    	output.document.write("</h2><p /><table>");
    	for (i=1; i<=found[0];i++)
    		{
    		output.document.write("<tr><td class=tables width=25>");
    		output.document.write("<h3 class=tablehead>");
    		output.document.write("" +i +"");
    		output.document.write("<td class=tables width=525><h3 class=tablejust>");
    		itemp=found[i];
    		output.document.write(desc[itemp].bold() +"<br>" +
    		links[itemp].link(links[itemp])+"<br>");
    		temp= (matched[itemp]/keywords[0])*100
    		matched[itemp]=0
    		} 
    	found[0]=0;
    	output.document.write("</table>");
    	}
    output.document.write('<hr size=1  color=cccccc>');
    output.document.write('<img src=images/icon.jpg>');
    output.document.write('</tr>');
    output.document.write('</tr>');
    output.document.write('</table>');
    output.document.write ("</body></html>"); 
    output.document.close();
    }

    Thanks!

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    basic HTML

    <a href="foo.html" taget="frameName">

    JavaScript:

    parent.frameName.location.href = "foo.html"

    You also may want to look into document.createElement instead of document.writes.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by A1ien51 View Post
    basic HTML

    <a href="foo.html" taget="frameName">

    JavaScript:

    parent.frameName.location.href = "foo.html"

    You also may want to look into document.createElement instead of document.writes.

    Eric
    I am truly in idiot lode tonight...

    I wrap the html link around the 'submit' image in my search form, yes?

    And where do I place the javascript?

    I am not familiar with document.createElement, but I will take a look into it.

    Thanks for your help!

  • #4
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    Ah I thought you wanted the links to open up in a new frame. You want the results.

    You would want to do the document.writes to the new frame

    parent.frameName.write("foo");

    Best thing would be createElement, appendChild

    I have a little function here: http://pascarello.com/examples/createElement.html

    And you would do something like

    parent.frameName.body.appendChild(t2);

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #5
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by A1ien51 View Post
    Ah I thought you wanted the links to open up in a new frame. You want the results.

    You would want to do the document.writes to the new frame

    parent.frameName.write("foo");

    Best thing would be createElement, appendChild

    I have a little function here: http://pascarello.com/examples/createElement.html

    And you would do something like

    parent.frameName.body.appendChild(t2);

    Eric
    I don't underdstand your answer 100%, I was just looking for a quick change to the existing code to spit the results out in a different frame to the one the search form lives in...

    So 'parent.frameName.write("foo");' looks to be the part I am interested in - can this be quickly incorporated into the existing code, or is there another way that you can see?

    I'm not really looking to change the way the rest of the code runs at this point.

  • #6
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    that is just like you output.document.write....

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]


  •  

    Posting Permissions

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