Solved

jquery autocomplete works initially but fails after redraw

Posted on 2009-06-28
6
721 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
  • 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now