SF23103 Posted August 27, 2018 Share Posted August 27, 2018 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> Quote Link to comment https://forums.phpfreaks.com/topic/307645-alternative-to-onchange-when-using-autocomplete/ Share on other sites More sharing options...
maxxd Posted August 27, 2018 Share Posted August 27, 2018 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. Quote Link to comment https://forums.phpfreaks.com/topic/307645-alternative-to-onchange-when-using-autocomplete/#findComment-1560537 Share on other sites More sharing options...
SF23103 Posted August 27, 2018 Author Share Posted August 27, 2018 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 ? Quote Link to comment https://forums.phpfreaks.com/topic/307645-alternative-to-onchange-when-using-autocomplete/#findComment-1560538 Share on other sites More sharing options...
SF23103 Posted August 27, 2018 Author Share Posted August 27, 2018 Just found onfocusout - works great! Quote Link to comment https://forums.phpfreaks.com/topic/307645-alternative-to-onchange-when-using-autocomplete/#findComment-1560539 Share on other sites More sharing options...
maxxd Posted August 28, 2018 Share Posted August 28, 2018 Ah - yes, blur will occur on focus in and focus out. Forgot about that, but glad you figured out the trigger you needed! Quote Link to comment https://forums.phpfreaks.com/topic/307645-alternative-to-onchange-when-using-autocomplete/#findComment-1560567 Share on other sites More sharing options...
requinix Posted August 28, 2018 Share Posted August 28, 2018 Use oninput. Quote Link to comment https://forums.phpfreaks.com/topic/307645-alternative-to-onchange-when-using-autocomplete/#findComment-1560571 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.