I'm on way of building a script like FB search box suggestion. Where, i've an INPUT box where user can enter a name.. and, as soon as user enter a name some suggestion will automatically appear under the INPUT box. All the suggestion, will appear inside an DIV. The code which i'm using is like this...
<input name="Emp_Name" id="emplyoee_search">
<div class="list"></div>
The suggestion list which i'm inserting inside that DIV().. i'm getting that by ajax & using jquery.HTML() i'm inserting those list inside of that DIV().
The suggestion list HTML code which i'm inserting in that DIV() is some thing like this..
<div class="listItem" align="left">Sunit K Marwah</div>
<div class="listItem" align="left">Sunit Maurya</div>
Now, the thing happening is.. i'm successfully able to build the suggestion list inside that DIV(). But, where i'm getting stuck is.. when some one click on any particular suggestion list(names) then, a javascript event need to be fire & the name need to be appear in the given INPUT box.
For java script event firing i'm using JQuery.HTML() & the code is like this..
$("div.listItem").click(function () {
var string = $(this).text();
alert(string);
//console.log(string);
});
But, my problem is.. i can successfully shows the list but when i click on the any particular name from suggestion list the java-script event is not firing & i can't able to catch the name.
I'm not a java-script xpert. So, don't know what exactly going wrong at where. Need some help.
Regards