Jump to content

alternative to onchange when using autocomplete


SF23103

Recommended Posts

Hello,

I have a form that is using Google's autocomplete for addresses.  I want the address they entered to appear in a paragraph of text at the bottom of the form. It works great when the user enters text manually.  Unfortunately, when the user selects an autocomplete result option, it does not update the paragraph text with the autocompleted result.  I did some reading and see that is normal, and onkeyup, onchange, etc. don't work with programmatically entered text.  Is there an alternative that can do what I want it to do?

 

<input id="searchTextField" name="Premise_Address" type="text" size="50" placeholder="Enter a location" autocomplete="on" runat="server" onkeyup="getVals(this, 'text');">


<p id="pAddressTextInput"></p>/>  

 

  <script>
        function getVals(formControl, controlType) {
            switch (controlType) {
                case 'text':
                    // Get the value for a text input
                    var value = $(formControl).val();
                    $("#pAddressTextInput").text(value);
                    break;
             }
        }
    </script>

 

Link to comment
Share on other sites

Have you tried the blur() event on the field? I can't guarantee it'll do what you want (I'm away from my computer right now), but I'm pretty sure that element.onblur() fires when a form field autocompletes as well as when the user navigates away from that field.

Link to comment
Share on other sites

Thanks for the suggestion!  I just tried changing onkeyup to onblur and got a *similar* result.  The only difference is that with onblur, if you tab or click out of the input box and then tab or click back into it, then it will update.  Getting closer ?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.