Need help with autocomplete script!

6 posts by 2 authors in: Forums > CMS Builder
Last Post: September 13, 2019   (RSS)

By nmsinc - September 8, 2019 - edited: September 8, 2019

The script below was written by the pros at Interactive Tools a few years back and works great! 

The result of the code in red below is what is listed in the autocomplete and is what is now recorded upon file save. I still need this information to show, however I want the account number associated with the file recorded and not the associated text!

Any ideas?

Thanks - nmsinc

   <div class="form-group">
   <label for="debtor">Name of Debtor</label>
   <input name='debtor' class='form-control' id='debtor' />
   <script>
   $( "#debtor" ).autocomplete({  source: [
   <?php foreach (mysql_select("debtor", "agency ORDER BY debtor_name") as $Groups): ?>
   <?php if ($CURRENT_USER['agency'] == $Groups['agency']): ?>
   "<?php echo $Groups['debtor_name'];?> - <?php echo $Groups['debtor_address_1'];?>  <?php echo $Groups['debtor_city'];?> <?php echo $Groups['debtor_state'];?>",
   <?php endif; ?>
   <?php endforeach ?>
   ]});
   </script>
   </div>

nmsinc

By daniel - September 11, 2019

Hi nmsinc,

It looks like this is using the jQuery UI autocomplete function. If that's the case, you should be able to do something like the following to differentiate the value saved from the label displayed:

   $( "#debtor" ).autocomplete({  source: [
   <?php foreach (mysql_select("debtor", "agency ORDER BY debtor_name") as $Groups): ?>
   <?php if ($CURRENT_USER['agency'] == $Groups['agency']): ?>
   {
   value: "<?php echo $Groups['num']; ?>",
   label: "<?php echo $Groups['debtor_name'];?> - <?php echo $Groups['debtor_address_1'];?>  <?php echo $Groups['debtor_city'];?> <?php echo $Groups['debtor_state'];?>"
   },
   <?php endif; ?>
   <?php endforeach ?>
   ]});

Note that you may need to change some details to match your specific needs. Let me know if that gets you on the right track, or if you have any other questions!

Thanks,

Daniel
Technical Lead
interactivetools.com

By nmsinc - September 11, 2019

Hi Daniel,

I like how you did this, is their a means to keep the name in the search box and pass the value upon submission?

Also, please forward a payment link and payment suggestion. Your time is worth something!

Thanks - nmsinc

nmsinc

By daniel - September 12, 2019

Hi nmsinc

is their a means to keep the name in the search box and pass the value upon submission?

Could you explain this in a bit more detail? E.g. what is the current behaviour, and how would you like it to change?

Also, payment is not necessary, but your support is appreciated! You can always consider making a donation the next time you upgrade CMSB :) (https://www.interactivetools.com/upgrade/)

Thanks,

Daniel
Technical Lead
interactivetools.com

By nmsinc - September 12, 2019

Once the selection is made from the autofill script the box shows the value of the record a not the autofill label text!!

nmsinc