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

By nmsinc - September 8 - edited: September 8

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

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
PHP Programmer
interactivetools.com

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

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

nmsinc

Hi nmsinc,

Oh yes, I see now what you're talking about. I think there is a way to do something like how you want, but it's rather complex with this sort of autocomplete. It actually sounds like what you want is closer to a select box than a text field. I would recommend looking at using a select dropdown with the Select2 plugin (https://select2.org/). A select dropdown will let you use the value:label combination how you're wanting here, and the Select2 plugin adds some type-to-search functionality.

I hope that points you in the right direction; let me know if you have any further questions!

Thanks,

Daniel
PHP Programmer
interactivetools.com