• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: How to populate one dropbox changing other

How to populate one dropbox changing other 9 years 10 months ago #31639

There are 2 dropboxes. Both must be filled from MySQL tables.
The primary dropbox gets its values by static php code, placed in "items" section:
//<code>
// Prepare the empty array
$items = array();
// Prepare the database connection
$db = JFactory::getDbo();
 
// Keep this if you'd like a "Please select" option, otherwise comment or remove it
$items[] = "|-SELECT-[c]";
 
// Run the SQL query and store it in $results
$db->setQuery("SELECT FLD1 as val, FLD2 as txt FROM some_table");
$results = $db->loadObjectList();
 
foreach ($results as $result) {
  $value = $result->val;
  $label = $result->txt;
  $items[] = $value.'|'.$label;
}
 
// Multiple values are separated by new lines, so we need to do this now
$items = implode("\n", $items);
 
// Now we need to return the value to the field
return $items;
//</code>

It's working good.

When this primary dropbox is changed, secondary dropbox must be filled each time dynamically from other MySQL table using current value of primary dropbox as index in SQL query.

I put this code in "Additional Attributes" of primary dropbox:
onchange="PrimaryDropboxChange();" 

So I must create function PrimaryDropboxChange in section CSS/Javascript that will populate secondary dropbox.
<script type="text/javascript">
function PrimaryDropboxChange() {
var $CurrIndex = document.getElementById('PrimaryDropbox').value;
// $CurrIndex - is the value that must be used in sql-query in WHERE statement
// But how fill dropbox by SQL-query in javascript? 
 
}
</script>
But I don't know how to do it from javascript. All examples are using PHP code...
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!