I have a dropdown list that populate from Joomla database

define('_JEXEC', 1);
if (file_exists(dirname(__FILE__) . '/defines.php')) {
    include_once dirname(__FILE__) . '/defines.php';
if (!defined('_JDEFINES')) {
    define('JPATH_BASE', dirname(__FILE__));
    require_once JPATH_BASE.'/includes/defines.php';
require_once JPATH_BASE.'/includes/framework.php';
// Get a db connection.
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->where($db->quoteName('#__unclimbedpeaks.link_id')." = ".$db->quote($link_id));
$query->order('peak_id ASC');
$peaks_list = $db->loadColumn();
$peaks_select  = '<select name="name" id="peaks">';
$peaks_select .= '<option value="">-- Odaberi vrh --</option>';
// here we use the peak_name for the value, whereas usually you set the value to the id of the table row. we're assuming there won't be any double quotes in these names.
foreach($peaks_list as $p){
    $peaks_select .= '<option value="' . $p . '">' . $p . '</option>';  
$peaks_select .= '</select>';

<form name="lista" method="post" action="">
<?php echo $peaks_select; ?>

Is it possible to get the $result variable without using the submit button.

So, when a user selects a value from the dropdown list, that is $result = "selected value" without clicking on submit

Thanks in advance

  • 3
    You should google some introductions to POST, GET and AJAX so you can get your head around when code runs during the request-response lifecycle. Once you've got that clear then you might write an event listerner to listen to the change event of the select and either submit the form via a regular post or get or use post or get via ajax. Jan 19, 2018 at 22:41

1 Answer 1

  1. Bind into onChange event on your select. In that event create Ajax request using com_ajax.
  2. In your module helper create a method that will handle the request and return output to com_ajax.

The whole process of processing requests to modules and plugins you have described in here

  • @Midhat it appears that you have abandoned this page. You are the only person who can mark this question as resolved. Artur has given you the correct advice. If this has solved your problem, please award his answer the green tick. If you need more specific support, please edit your question to show where you are stuck and leave a comment to Artur so that he can update his answer. Jan 28, 2019 at 4:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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