Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

js simple search function, need some help to modify

Status
Not open for further replies.

chriskq

Technical User
Oct 6, 2005
6
AU
hi all,

im just still getting into web design and i have finished this site,
Im a little bit unhappy about how the search function (upper right) opens the results in a new window. i have tired playing with the script to make it open results on a new page but in the same window.
[to test type "press" to see results]

code for the script can be found here:

i tired playing with this line.
Code:
Code:
win = window.open("","results","");
im not even sure how to tell the script where to place the results html in the page i want it too (ie results.php in a certain div)

can someone pls point me in the right direction
cheers
Chris
 
Hi,

I couldn't discover the exact target. But there are two form elements cascading. When you click a button in inner form element, not the inner form's submit but the outer form's submit is working as I see. If you remove the outer form element out and leave the inner one, it will appear in a new window. You can check this out.
But I'm not sure if this will perform the search operation as it should or not. Because your search function in this sample seems to be handled by controller.php not the javascript code...

Regards,
ali
 
thanks for answering CaptainPlus.

ur slightly off in what you said. Yes i do have two seperate form tags on my page 1. for email registration updates, 2. for the search function.

the search function does not get processed by controller.php but is handelled by javascript (that can be seen using view source on
and until i get my php skills up with mySql i have to rely on this js version.

so yea im still really stuck on getting the results on OPEN a new PAGE, but in the same window (how a search function should work - not open the results in a NEW window)

cheers all
 
Hi

The problem is not the line you quoted, but the next :
Code:
win.document.write(page);
If you want the results in the same window, then the new document ( designated for results but initially empty ) will replace the old one ( with search form and results ) before the results can be turned into document.

So no, with that strategy you can not solve it having only one document opened at a time. You may consider messing with frames, but better not.

I recommend to study PHP for one day, after that you will be able to implement that basic search functionality. The PHP manual and forum434 ( PHP ) provides enough help for such simple task even for unexperienced programmers.

Feherke.
 
Hi

Now this is completely off-topic.
Code:
<html>
<head>
<title>Search Results</title>
</head>
<body bgcolor="white">
<center>
<table border="0" cellspacing="10" width="60%">
<?php
// "Page Name","path","Page Title","Many,Key,Words","Descriptive Comments"
$item=array(
  array("pressRelease_1.php","","Press Release 1","press,customers,company,journalists,relationships,media,reporter","Online press rooms drive customers, deals, investments - and powerful media coverage."),
  array("pressRelease_2.php","","Press Release 2","press,journalists,website,Australians,media","Corporate Websites fail to deliver answers for US based journalists."),
  array("pressRelease_3.php","","Press Release 3","press,journalists,website,Australians,media,solution,press room,event,overseas","Don't leave home without a trade show press room.")
);
$txt=split(" ",$_GET[srchval]);
$fnd=array();
$total=0;
for ($i=0;$i<count($item);$i++) {
  $fnd[$i]=0; $order=array(0,4,2,3);
  for ($j=0;$j<count($order);$j++)
  for ($k=0;$k<count($txt);$k++)
  if (strpos(strtolower($item[$i][$order[$j]]),$txt[$k])!==false && $txt[$k]!="")
  $fnd[$i]+=($j+1);
}
for ($i=0;$i<count($fnd);$i++) {
  $n=0; $w=-1;
  for ($j=0;$j<count($fnd);$j++)
  if ($fnd[$j]>$n) { $n=$fnd[$j]; $w=$j; }
  if ($w>-1) $total+=show($w,$n);
  $fnd[$w]=0;
}
function show($which,$num)
{
  global $item;
  $link=$item[$which][1].$item[$which][0];
  echo "<tr><td><a href='$link'>".$item[$which][2]."</a> Score: $num<br>".$item[$which][4]."<br>$link</td></tr>";
  return 1;
}
?>
</table>
<br>Total found: <?php echo $total; ?><br><br>
</center>
</body>
</html>
Code:
<form action="search.php">
<input type="text" name="srchval" value="searchable term" class="inputSearch" onfocus="setValue(this);" onblur="checkValue(this,'searchable term');">
<input type="submit" value="" class="updateSearch">
</form>

Feherke.
 
hi feherke,

wow is that like a quick solution - the code u provided?
if so - a thousand thankyous to u :)

ill give that a shot 2nit wen im home from work
 
Hi

Yes, I took all the pleasure of rewriting from you.

My point was to show that the job was mostly changing the syntax. So you should be more confident in your programming skill. :)

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top