0

I have a dropdown list that populate from Joomla database

define('_JEXEC', 1);
define('DS', DIRECTORY_SEPARATOR);
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->select('peak_name');
$query->from($db->qn('#__unclimbedpeaks'));
$query->where($db->quoteName('#__unclimbedpeaks.link_id')." = ".$db->quote($link_id));
$query->order('peak_id ASC');
$db->setQuery($query);
$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; ?>
    </form>

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

1
  • 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 '18 at 22:41
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

1
  • @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.
    – mickmackusa
    Jan 28 '19 at 4:38

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.