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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP/Javascript for intuitive popup menu search

Status
Not open for further replies.

PilotMike

Programmer
Jul 14, 2003
31
US
Hello all.

I'd like to create a real-time, intuitive/predictive search field on a web form. I have a list of names I query into an array from a MySQL database which number more than 1200. Creating a standard popup would be tedious to scroll through. I could also have the user enter in a partial name and click on a "search" button, but I would really like something a little faster and less obtrusive.

What I'd like to accomplish is to have a text field that, as the user types part of the name, would present a list of matches from the 1200 entries...either in a textarea next to the entry field or as a popup menu.

I haven't found much on using php variables from within javascript, so I'm not entirely sure that it can even be done, so that's the first question I'd like to ask. I really need to get to the array of names I've loaded in from a MySQL query.

Any ideas would be greatly appreciated.
Thanks!
 
u need a combo of PHP and javascript and HTML. u have to use <iframes>.

in ur textbox's onkeydown event submit the IFRAME to ur search page along with the box's content

parent.frames.IFRAMENAME.src="Search.php?strng="+document.FormName.TextBoxName.value

in ur php file u could get the value using $_GET method.

This should work...

Known is handfull, Unknown is worldfull
 
Did you have any luck with this? It sounds like it would work, though Im not sure if it'd be quick enough on the refresh..

I'd need to do this in ASP, though that's pretty much 1:1 w.PHP I think. If anyone can provide full pseudo/real code for this that would be great.

I'd be most interested in the JavaScript that would be querying the DB onKeyDown/code to have the iFrame submit everytime, as I'm a bit weak no the JavaScript.
 
How about this?
Code:
<!-- search.html -->
<html>
<head>
<title>Search</title>
<script type="text/javascript">
<!--

function doSearch(fld)
{
  document.getElementById("ifr").src = "srch.php?q=" + fld.value;
}

// -->
</script>
</head>
<body>
<form>
 <input type="text" name="s" onkeydown="doSearch(this);"><br>
</form>
<iframe src="" width="400" height="400">
Your browser does not support iframes! Click here for the <a href="noframes.html">frameless page</a>.
</iframe>
</body>
</html>
Code:
// srch.php
<?php
$q = $_GET['q'];

// connect to database
$r = mysql_result("SELECT * FROM searches WHERE fld LIKE '$q%'");
// do stuff with $r
?>

--Chessbot

"In that blessed region of Four Dimensions, shall we linger on the threshold of the Fifth, and not enter therein? Ah, no! [...] Then, yielding to our intellectual onset, the gates of the Sixth Dimension shall fly open; after that a Seventh, and then an Eighth -- --" Flatland, A. Square (E. A. Abbott)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top