Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi when i use jquery autocomplete in a page its working well.Now i have a page which have two field.one is for searching subject and another is for searching institute.When i use jquery autocomplete in both fields it can not work.only first field work second field can not work.My code is given below:

HTML
<script type="text/javascript">
$("#"+fieldID+"").autocomplete({
	source: function(request, response) {
            $.ajax({
                url: "autocomp3.asp",
                dataType: "json",
                data: {
                    term : request.term
                },
                success: function(data) {
					
                    response(data);
                }
            });
        },
        minLength: 3,
        delay: 300,
		select: function (event, ui) {
				//$("#txtAllowSearch").val(ui.item.label); // display the selected text
				$("#"+hiddenIdField+"").val(ui.item.id); // save selected id to hidden input
    	}
    });
</script>


<script type="text/javascript">
  
  var fieldID ="";
  
   
   function SetParam(fID)
   {
	  fieldID       = fID;
	  
   }
  
</script>


<input type="text" id="subject"   >
<input type="text" id="institute" >


plz help me how to solve this problem

What I have tried:

i use this
<input type="text" id="subject" >
<input type="text" id="institute" >

onclick() to set the id dynamic
Posted
Updated 10-May-16 0:39am
v2
Comments
ZurdoDev 10-May-16 7:22am    
Because it won't work like this. Your call to wire up autocomplete is not inside a function which means it executes when the page loads. Then you change the fieldID parameter but inside a function and don't call the wireup code for autocomplete.
Member 9361273 10-May-16 7:29am    
Thank you for your answer.Then how can i solve this problem
ZurdoDev 10-May-16 7:39am    
Put them in functions and call when needed.
Member 9361273 10-May-16 7:49am    
Thank you.But i have another solution
i use
$(".person_input").each(function(){

$(this).autocomplete();
});
ZurdoDev 10-May-16 7:52am    
If they all have that same class, then great. Good use of jquery.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900