Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-21-2012, 11:23 AM   PM User | #1
codernoob
New Coder

 
Join Date: Sep 2012
Posts: 26
Thanks: 17
Thanked 0 Times in 0 Posts
codernoob is an unknown quantity at this point
Question How to Display search results without a Frame.

Hi,

I am using a Javascript code snippet for my website for doing page searches on a site - on local system network (not hosted/no php). The files are pre-indexed and thus searched.

With the help of 'Xelaho' who was very helpful, I was able to add two types of search options - a Keyword entry based one and a 'Dropdown' choice one.

Both the options work well when they are used separately, But now my issue is to integrate these both options on a single page without using frames for displaying the results for - Keyword entry and Dropdown search.

I believe something in the code prevents the search data to show up or either of the controls for the search.

Can anyone help?

The code for normal keyword entry search is (instructions to not change 's')

Code:
</script>
</head>
<body>
<form>
<table width=100% cellpadding=5 style="background-color:#EFF;border:2px solid #069"><tr><td align=center>
<em>Site Search</em><br>
<input type="Button" value="Go!" onClick="return NS()">
<input type=text name="s" size=24 onKeyDown="if(event.keyCode==13)return NS()">&nbsp;<input type="Button" value="Go!" onClick="return NS()">
</td></tr></table>
</form>
<script>
The code for Dropdown search is :

Code:
<select name="s">
  <option value="value1">Value 1</option> 
  <option value="value2">Value 2</option>
  <option value="value3">Value 3</option>
</select>
this is the whole code for the search

Code:
<title>Site Search</title>
<style type="text/css">
<!--
body {color:#000000;font:10pt Verdana,Tahoma,Arial,Helvetica,sans-serif}
em {color:#0000FF;font:bold 10pt Verdana,Tahoma,Arial,Helvetica,sans-serif}
b {font-weight:bold}
-->
</style>
<script language="JavaScript">
<!--
function f(fn,ft,fd){
 this.fn=fn;
 this.ft=ft;
 this.fd=fd;
}
var Fs=new Array (
new f
( 
**//indexed words/pages/code comes here**//

   );
var FN=Fs.length, WN=Ws.length, BW=window.opener;
var AR=new Array(FN), AI=new Array(FN), M2=FN>1563;
function Let(c){return c>='a'&&c<='z'||c>='0'&&c<='9'||c>'';}
function Dig(s){
 for(var i=0;i<s.length;++i){
	var c=s.charAt(i);
	if(c>='0'&&c<='9') return 0;
 }
 return 1;
}
function C(l){
 if(BW && !BW.closed) {BW.location.href=l;BW.focus();}
 else BW=window.open(l,"");
}
function AW(s){
 var i,n;
 for(i=0;Let(s.charAt(i));++i);
 if(s.charAt(i)==' ') ++i;
 for(var m=1;i<s.length;){
	n=s.charCodeAt(i++)-35;
	if(n<0) n=(n+20)*92+s.charCodeAt(i++)-35;
	else if(M2) n=n*92+s.charCodeAt(i++)-35;
	AI[n]+=m++;
 }
}
function MK(s,n){
 var i;
 for(i=0;i<FN;++i) AI[i]=0;
 s=s.replace(/\*/g,'[^ ]*');
 s=s.replace(/\?/g,'[^ ]');
 s = '^'+s;
 for(i=0;i<WN;++i) if(Ws[i].search(s)==0) AW(Ws[i]);
 for(i=0;i<FN;++i) if(n) AR[i]*=AI[i]; else AR[i]=AI[i];
}
function MT(){
 var c,i,n,t="",ss="",s=document.forms[0].s.value.toLowerCase()+' ';
 for(i=0;i<FN;++i) AR[i]=M;
 for(i=n=0;i<s.length;++i){
	c=s.charAt(i);
	ss+=(c=='<')?"&lt;":c;
	if(Let(c)||c=='*'||c=='?') t+=c;
	else {
		if(t.length>L&&(D||Dig(t))) MK(t,n++);
		t="";
	}
 }
 t='You searched for "<b> '+ss+'</b>".<p>\n';
 for(n=0;;++n){
	var m=0,im=-1;
	for(i=0;i<FN;++i) if(AR[i]>m) m=AR[im=i];
	if(im<0){
		if(n==0) t+="<div align=center><p><b>No results found.</b></div><p>\n";
		break;
	}
	AR[im]=0;
	t+=("<b>"+(n+1)+".</b> <a href='javascript:C(\""+Fs[im].fn+"\")'>"+Fs[im].ft+"</a><br>\n"+Fs[im].fd+"<p>\n");
 }
 return t;
}
function NS(){
 if(document.getElementById) document.getElementById('txt').innerHTML=MT();
 else document.forms[0].submit();
 return false;
}
function SS(){
 if(location.search){
	var o="**";
	var t="";
	for(var i=3; i<location.search.length; t+=c) {
		var c=location.search.charAt(i++);
		if(c=='+') c=' ';
		if(c=='%') {
			var v=parseInt(location.search.substring(i,i+2),16);
			if(v<128) c=String.fromCharCode(v);
			else c=o.charAt(v-128);
			i+=2;
		}
	}
	document.forms[0].s.value=t;
 }
}
//-->
</script>
</head>
<body>
<table width=100% cellpadding=5 style="border: 2px solid #069"><tr>
  <td align=center><em>SEARCH </em><br>
  <SELECT NAME="droplist">
  <OPTION SELECTED="SELECTED" VALUE=" keyword ">keyword</OPTION>
  <OPTION VALUE="meta">Meta</OPTION>
  <OPTION VALUE="Query">Query</OPTION>
  <OPTION VALUE="http://www.yoururl2com">Your Discription2</OPTION></SELECT>
  <input type="Button" value="Go!" onClick="return NS()"> 
  <input type=text name="s" size=24 onKeyDown="if(event.keyCode==13)return NS()">&nbsp;<input type="Button" value="Go!" onClick="return NS()">
</td></tr></table>
<script>
<!--
if(window.opener) document.write("<div align=center><a href='javascript:window.close()'>Close window</a></div><p>");
//-->
</script>
<div id=txt>
<script>
<!--
SS();
document.write( MT() );
//-->
</script>
</div>
</body>
</html>

Any help is much appreciated!!!

Thanks again
codernoob is offline   Reply With Quote
Old 09-21-2012, 06:17 PM   PM User | #2
codernoob
New Coder

 
Join Date: Sep 2012
Posts: 26
Thanks: 17
Thanked 0 Times in 0 Posts
codernoob is an unknown quantity at this point
any suggestions folks?
codernoob is offline   Reply With Quote
Old 09-21-2012, 06:21 PM   PM User | #3
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 453 Times in 451 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
so, will the go button on the left just return results from the dropdown and the go button on the right just results from the input box?

Or if not, how else will the code know what it is supposed to be searching for?
xelawho is offline   Reply With Quote
Users who have thanked xelawho for this post:
codernoob (09-21-2012)
Old 09-21-2012, 09:13 PM   PM User | #4
codernoob
New Coder

 
Join Date: Sep 2012
Posts: 26
Thanks: 17
Thanked 0 Times in 0 Posts
codernoob is an unknown quantity at this point
the go button on the right returns the results (keyword search), I havent been able to join 'em together on a single page .

tbh ,i dont really have the knowledge to do either :S
codernoob is offline   Reply With Quote
Old 09-21-2012, 09:45 PM   PM User | #5
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 453 Times in 451 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
no, what I'm asking is this: say the user types something into the text box then changes their mind and selects something from the dropdown. They press the go button - how does the code know which value to search for? Is there a preference? Or does the search from the dropdown start as soon as the user chooses an option, and they only have to press the button if they're using the textbox?
xelawho is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 05:22 PM.


Advertisement
Log in to turn off these ads.