• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 753
  • Last Modified:

jquery autocomplete works initially but fails after redraw

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...
    extraParams:{mytype:function() {return formPartsUsed.request_type[0].checked;},itemnum:function() {return formPartsUsed.item_num.value;}},
    hideCallback : function() {document.getElementById("pleasewait").style.visibility="hidden";},
Here is a simplified example: (Oracle Pl/SQL)
<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
---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';

Open in new window

  • 4
  • 2
1 Solution
Michel PlungjanIT ExpertCommented:
Not sure you want to submit that form - it could unload the page

Why not call the ajax submit from the button instead?
ericdalrympleAuthor Commented:
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.
ericdalrympleAuthor Commented:
trying this attach file functionality again... dont see where it can be viewed from the first time i did it.
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Michel PlungjanIT ExpertCommented:
This sure looks like a submit to me
ericdalrympleAuthor Commented:
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
var sFrmData = "";
var sURL="myurl";
function doAjax(sURL,sFrmData){';
    type: "POST",
    url: sURL,
    data: sFrmData,
    success: function(ajaxResponse){

Open in new window

ericdalrympleAuthor Commented:
I just recoded everything to not refresh the tab where the autocomplete field lives. Still an issue but I worked around it for now.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now