Can u please help me to have some codes for "auto-complete" in text-box that gets the data from the database
Tnx :)
Leosghost
3:28 am on Jun 18, 2012 (gmt 0)
search "javascript auto-complete"
NoobLike
4:53 am on Jun 18, 2012 (gmt 0)
Is there a code for this in PHP. I need to write it in PHP form :)
rocknbil
3:54 pm on Jun 18, 2012 (gmt 0)
You can put Javascript into PHP files, but auto complete is a function of the browser, not server side programming, and the only access to the browser itself is via client side scripting - as said, Javascript (or VBscript.)
whatson
12:52 pm on Jun 20, 2012 (gmt 0)
<html> <head> <script type="text/javascript"> function findmatch() { if (window.XMLHttpRequest){ xmlhttp = new XMLHttpRequest(); } else { xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); } xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { document.getElementById('results').innerHTML = xmlhttp.responseText; } } xmlhttp.open('GET', 'search.inc.php?search_text='+document.search.search_text.value, true); xmlhttp.send(); } </head> <body> <form id="search" name="search"> Type a name:<br> <input type="text" name="search_text" onkeyup="findmatch();"> </form> <div id="results"></div> </body> </html>
****************search-inc.php**************
<?php
if (isset($_GET['search_text'])) { echo $search_text = $_GET['search_text']; }
if (!empty($search_text)) {
if (mysql_connect('localhost','root','')) { id (mysql_connect_db('a_database')) {
$query = "SELECT `firstname` FROM `names` WHERE `name` LIKE '".mysql_real_escape_string($search_test)."%'"; $query_run = mysql_query($query);
while ($query_row = mysql_fetch_assoc($query_run)) echo $name = $query_row['name'].'<br>';