?
Solved

jquery autocomplete works initially but fails after redraw

Posted on 2009-06-28
6
Medium Priority
?
738 Views
Last Modified: 2012-05-07
I uploaded an image to help explain... called autocompleteproblem.gif but not sure where that shows up...

I am using jorn version of jquery autocomplete and have a problem.
I have a page that has a div containing a form (and my auto complete field). Initially, this div is populated when the page is drawn, however, the user can trigger an ajax request that, upon returning, refills the contents of the div with updated info.
On The initial load, my autocomplete field works great. However, after the div contents are reloaded via ajax... nothing happens when i type in my auto complete field.

I placed an alert() into autocomplete.js in the function onChange(crap, skipPrevCheck) {. On initial load, when i type in my field, i get the alert. however, the alert does not fire the second time.

something to note... in my ajax callback, when I am refilling the contents of the div via ajax, I am using innerHTML to set the contents... I have to escape quotes etc.
e.g. mydiv.innerHTML="the entire form including my autocomplete field"

is there something to do with the dom ... or CSS... where a pointer to my autocomplete field is created initially... then when the new version of the div tries to do it again... there is a conflict?
Obviously I am very new to this stuff...
$("#item_num").autocomplete(
    "http://myurl.com&",
     {
    delay:400,
    minChars:2,
    matchSubset:1,
    maxItemsToShow:12,
    matchContains:1,
    extraParams:{mytype:function() {return formPartsUsed.request_type[0].checked;},itemnum:function() {return formPartsUsed.item_num.value;}},
    hideCallback : function() {document.getElementById("pleasewait").style.visibility="hidden";},
    cacheLength:0,
    onItemSelect:selectItem,
    autoFill:false
  }
);
 
 
Here is a simplified example: (Oracle Pl/SQL)
----INITIAL PAGE LOAD---
<div id=mydiv>
<form name=form1 method=post action="ajax post">
<input type=text class="ac_input" alt="Item#" name="item_num" id="item_num">
<input type=button onclick="form1.submit();">
... more div content
</form>
</div>
 
---AJAX REQUEST CALLBACK (replaces the div with new results.)---
strContent := '<form name=form1 method=post action="ajax post">';
strContent := strContent || '<input type=text class="ac_input" alt="Item#" name="item_num" id="item_num">';
strContent := strContent || '<input type=button onclick="form1.submit();">';
strContent := strContent || '... more div content';
document.getElementById("mydiv").innerHTML=REPLACE(strContent,'"','\"');

Open in new window

0
Comment
Question by:ericdalrymple
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24734757
Not sure you want to submit that form - it could unload the page

Why not call the ajax submit from the button instead?
0
 

Author Comment

by:ericdalrymple
ID: 24737255
The page has tabs. I have a single div that holds the contents of a tab. When user clicks on a different tab I use Ajax to get the contents for that tab and fill the div... Not really doing a form submit... Using Ajax to retrieve contents of div.
When the page draws initially, my div that contains the autocomplete field works fine. When I grab the exact same contents and fill the div(user clicked a different tab then returns to original tab) it stops working.
0
 

Author Comment

by:ericdalrymple
ID: 24737684
trying this attach file functionality again... dont see where it can be viewed from the first time i did it.
autocompleteproblem.jpg
0
DFW AZURE MEETUP TONIGHT FRI 6PM

We will be discussing what Azure Stack is, how does it fit into the suit of offerings that Azure has currently, and where can it fit into your organizations technology stack. We will also be discussing limitations of the platform while covering various applicable scenarios.

 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24738924
This sure looks like a submit to me
onclick="form1.submit();"
0
 

Author Comment

by:ericdalrymple
ID: 24738997
i just put the button with submit as an example... sorry... when the user changes tabs it fires off the ajax below. When it comes back it makes the div visible and innerHTML the contents of the tab.

anyway... the problem is that after this is done... the autocomplete stops working.

thanks for your reply...
function getPartsRemoved(){
//hide the div
document.getElementById("bottomTabDiv").style.visibility="hidden";
var sFrmData = "";
var sURL="myurl";
doAjax(sURL,sFrmData);
}
 
function doAjax(sURL,sFrmData){';
$.ajax({
    type: "POST",
    url: sURL,
    data: sFrmData,
    success: function(ajaxResponse){
    eval(ajaxResponse);
  }
 });	
}		

Open in new window

0
 

Accepted Solution

by:
ericdalrymple earned 0 total points
ID: 24898895
I just recoded everything to not refresh the tab where the autocomplete field lives. Still an issue but I worked around it for now.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question