2

I searched and searched but could not find anything similar. Pointers if I'm wrong, please.

Not sure how to post this without supplying 'a wall of code'. Code is PHP, javascript ajax, jquery autocomplete function

Using pseudocode...This works perfectly

----start
function <jquery autocomplete> - return term

input jobtype onblur fetchdata  (ajax call to render additional inputs based on jobtype chosen)

input sitename - using autocomplete, works perfectly

<additional inputs rendered from ajax call here>

---end

Autocomplete will not work in this scenario:

----start
function <jquery autocomplete> - return term

input jobtype onblur fetchdata  (ajax call to render additional inputs based on jobtype chosen)

</start additional inputs rendered from ajax call here>
    input sitename - using autocomplete, doesn't work at all
    additional ajax rendered inputs here
</end additional inputs>

---end

Also tried this unsuccessfully

Autocomplete will not work in this scenario:

----start
input jobtype onblur fetchdata  (ajax call to render additional inputs based on jobtype chosen)

</start additional inputs rendered from ajax call here>
    function <jquery autocomplete> - return term

    input sitename - using autocomplete, doesn't work at all

    additional ajax rendered inputs here
</end additional inputs>

---end

So, if I have the site name field on the page, autocomplete works, so the code isn't broken.

If I try to render the site name input along with others, autocomplete will not work. Nothing happens, no errors, nothing. I tried rendering the function along with the field which did not work either.

When I used firebug to inspect the page upon the ajax call rendering, everything looked perfect which is the confounding part.

I'll provide code if the issue is not apparent in my method...

This is the js function. Maybe I need to add something to allow it to work with ajax rendered inputs?

<script>
    $(function() {
        $( "#sitename" ).autocomplete({
            source: 'acsitename.php'
        });
    });
</script>

TIA for any help.

Owen Parker
  • 253
  • 2
  • 12
  • Is it possible that you are binding to a DOM element that is not available during document ready? – frz3993 Jul 27 '16 at 19:04
  • That sounds exactly like what I am doing @frz3993. My depth of knowledge of javascript is non-existent, but I can read and have been doing some learnin' based on your very logical comment. However, after many iterations, I have not had any luck figuring out how to resolve my situation, even knowing possibly what is wrong. From a number of SO posts, I have determined (mistakenly or not) that I need to use on(). This post [link](http://stackoverflow.com/questions/9693758/how-do-you-bind-jquery-ui-autocomplete-using-on) led me to this code – Owen Parker Jul 28 '16 at 01:42
  • `` Still nothing... – Owen Parker Jul 28 '16 at 01:46
  • The first parameter for `on` is the event(click, keyup, keydown...), the second is the selector for the DOM element listened to (eg `"#input_field"`), the third is the function. So, instead of `on("keydown.autocomplete"..`, it should be `on("keydown"...` – frz3993 Jul 28 '16 at 17:15
  • Thanks very much for that @frz3993. I spent a couple hours trying every combination to no avail. For all I read, I never came across an actual explanation, just many examples. I finally did the unthinkable and gave up and redesigned the damn thing to fork to two separate scripts versus trying to make both work on the same page. I will use this knowledge to get it working, however. I'll mark this and add more detail at the same time. – Owen Parker Jul 29 '16 at 18:44

0 Answers0