Jump to content
SF23103

alternative to onchange when using autocomplete

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>

 

Share this post


Link to post
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.

Share this post


Link to post
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 ?

Share this post


Link to post
Share on other sites

Ah - yes, blur will occur on focus in and focus out. Forgot about that, but glad you figured out the trigger you needed!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • 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.