Note that there are some explanatory texts on larger screens.

plurals
  1. POApply autocomplete to dynamically generated textboxes with data from database
    text
    copied!<p>I have gone through many ques here on stackoverflow with regard to my query here but could not apply them to my problem.</p> <p>Hence I am giving here my files that I have been using.</p> <p>I am successfully able to use autocomplete with a static textbox. I get the data from the database. But however I am not able to figure out how to do it for dynamically generated textboxes. I want autocomplete feature to be implemented for dynamically generated textboxes with data from databases</p> <p>here are my files:</p> <p>index.php</p> <pre><code> &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;Auto Complete Input box&lt;/title&gt; &lt;link rel="stylesheet" type="text/css" href="jquery.autocomplete.css" /&gt; &lt;script type="text/javascript" src="jquery.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="jquery.autocomplete.js"&gt;&lt;/script&gt; &lt;script&gt; $(document).ready(function(){ $("#name").autocomplete("autocomplete.php", { selectFirst: true }); }); &lt;/script&gt; &lt;script&gt; function addForm(){ $("#forms").append( "&lt;form&gt;&lt;input type ='text' name='winner' id='winner'&gt;&lt;br/&gt;&lt;/form&gt;" ); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;label&gt;Name:&lt;/label&gt; &lt;input name="name" type="text" id="name" size="20"/&gt; &lt;input type="button" name="addmore" id="addmore" value="Add More Winners" onclick="addForm();"/&gt; &lt;div id = "dyanamic"&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>autocomplete.php</p> <pre><code> &lt;?php require 'config.php'; $q=$_GET['q']; $my_data=mysql_real_escape_string($q); //$mysqli=mysql_connect('localhost','root','','emp_db') or die("Database Error"); $sql="SELECT name FROM employee WHERE name LIKE '%$my_data%' ORDER BY name"; $result = mysql_query($sql) or die(mysqli_error()); if($result) { while($row=mysql_fetch_array($result)) { echo $row['name']."\n"; } } </code></pre> <p>?></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload