0

Using below code to display database values as drop down in rsjoomla

$items = "|Please Select[c]\n";
$db = JFactory::getDBO();
$db->setQuery("SELECT id, prod_name FROM __used_products ORDER BY prod_sorder ASC");
$result = $db->loadObjectList();
if($result)
foreach ($result as $r)
$items .= $r->id . '|' . $r->prod_name . "\n";

return rtrim($items);

However - as the drop down is of more than 200 items, is there a way for a user to start typing a word and the select box only shows possible matches?

For example, the drop down field has the following options:

  • Alto
  • Amaze
  • Wagon r
  • swift
  • i10
  • santro

Then if a user types in a - it should display matching results (Alto, Amaze)

  • if the provided answer solved your issue, please award it the green tick. If you still require support with your issue, please update the question with details on where you would like help. I personally would have elected to use Joomla's query building methods, and I would have returned the option data as an associative array instead of a pipe and newline delimited string so that it is easier to unpack. – mickmackusa Jan 27 at 5:16
1

Simple. You'll want to utilise jQuery Chosen which is shipped with Joomla.

Target a specific select box:

<?php JHtml::_('formbehavior.chosen', '.myclass'); ?>

<select class="myclass">
    // Options
</select>

Target all select boxes:

<?php JHtml::_('formbehavior.chosen', 'select'); ?>

<select>
    // Options
</select>

It will render something similar to the image below.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.