Bienvenido, Invitado
Recordarme

TEMA:

problem showing a select item populated with the database 8 meses 1 semana antes #271723

  • Avatar de Mirec
  • Mirec
  • Fuera de línea
  • Ultimate Breezer
  • Ultimate Breezer
  • Mensajes: 3262
  • Karma: 2
  • Gracias recibidas: 160
Hi,

oke, I will make an example for you and I will back to you as soon as possible!

If you have more questions, feel free to ask!

Regards,
Mirko

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

problem showing a select item populated with the database 8 meses 1 semana antes #271741

  • Avatar de Mirec
  • Mirec
  • Fuera de línea
  • Ultimate Breezer
  • Ultimate Breezer
  • Mensajes: 3262
  • Karma: 2
  • Gracias recibidas: 160
Hi,


in the example, we have two select list:

select list 1 - name-> customer
select list 2 - name -> modal

in the first select list, in Advanced of element scroll down to the section Action script select type custom, Action Change, and insert this code:
function ff_Customer_action(element, action)
{
    switch (action) {
        case 'change':
            jQuery.ajax({
                type: "POST",
                
                url: "<?php return JURI::root(true ); ?>/Select_list_Customer_Model.php",
                data: { code: ff_getElementByName('Customer').value},    
                success: function(data) {
                var obj = JSON.parse(data);
                var result = [];

    var keys = Object.keys(obj);
    keys.forEach(function(key){
        result.push(obj[key]);

    });
                        jQuery('#ff_elem370').empty();
                       
                       jQuery('#ff_elem370').append(jQuery('<option>', {
                                value: '',
                                text: 'Choose option'
                            }));
                       for (var i = 0; i < result.length; i++) { 
                           console.log(result[i]);
                           jQuery('#ff_elem370').append(jQuery('<option>', {
                                value: result[i],
                                text: result[i]
                            })); 
                        }
                }      
            });
            break;
        default:;
    } // switch
} // ff_Customer_action

then I create one PHP file and please put this file into Joomla root, content of the PHP file is:
<?php

define('_JEXEC', 1);
if (file_exists(__DIR__ . '/defines.php'))
{
    include_once _DIR_ . '/defines.php';
}
if (!defined('_JDEFINES'))
{
    define('JPATH_BASE', __DIR__);
    require_once JPATH_BASE . '/includes/defines.php';
}
require_once JPATH_BASE . '/includes/framework.php';


$db = JFactory::getDBO(); 

$code=$_POST['code']; // the value posted from the AJAX request above

$db = JFactory::getDBO();

$db->setQuery("Select Model From jos_Projects Where Customer = '$code' ");


$row =$db->loadColumn();
 if(!$row){
 	echo "error";
} else {

	echo json_encode($row);
}

?>


I do not in detail explain the code because as I see you understand the coding and I will let you that self try to do it on your FORM.

If you get to stuck, please let me know and I will help you!





Please download->unzip->and install it (BF->Configuration->Package Installer->select this xml file->Install Package).


Archivo Adjunto:

Nombre del Archivo: mypck_001171.zip
Tamaño del Archivo:11 KB


Regards,
Mirko
Adjuntos:

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

problem showing a select item populated with the database 8 meses 1 semana antes #271750

  • Autor del tema
  • Sherco
  • Fuera de línea
  • Junior Breezer
  • Junior Breezer
  • Mensajes: 34
  • Gracias recibidas: 2
OK, i have already seen this code, and already use it in my code, but i need an exemple with a two fields query return ( I want the value and text to be different in the option list).

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

Última Edición: Post by Sherco.

problem showing a select item populated with the database 8 meses 1 semana antes #271752

  • Avatar de Mirec
  • Mirec
  • Fuera de línea
  • Ultimate Breezer
  • Ultimate Breezer
  • Mensajes: 3262
  • Karma: 2
  • Gracias recibidas: 160
Hi,

sorry but I do not understand you well!

Could you a little better explain?

what exactly mean when you said 'example with a two fields query return ' ?


Regards,
Mirko

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

problem showing a select item populated with the database 8 meses 1 semana antes #271764

  • Autor del tema
  • Sherco
  • Fuera de línea
  • Junior Breezer
  • Junior Breezer
  • Mensajes: 34
  • Gracias recibidas: 2
list1(sidefab) options: populated with the database in the form initialization, i do not have any problem with that.

list 2(sidemodel) options: must be filled with sidemodel_name as text AND sidemodel_id as value


My select query , for the list2, is built to return those 2 fields (plus a third one which represent the sidefab index , but which is not used here so don't care about it), and works fine as i showed you with the previous attachments

the ajax query return string i have to work with to populate the list2 looks OK:
"Saphir","1","10"],["Serval","2","10"],["Sygma","3","10"],["Swan","4","10"

my problem is to fill list2 with the result and show it:
0;Saphir;1
0;Serval;2
.....

it should be something like
for(var i=0;i<result.length;i++){
console.log(result);
jQuery('#ff_elem410').append(jQuery('<option>',{value:result[1],text:result[0]}));

Does the line "console.log(result); is OK, or should it be result[index]

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

problem showing a select item populated with the database 8 meses 1 semana antes #271769

  • Avatar de Mirec
  • Mirec
  • Fuera de línea
  • Ultimate Breezer
  • Ultimate Breezer
  • Mensajes: 3262
  • Karma: 2
  • Gracias recibidas: 160
Hi,

oke, now I understand you!

hmm, I need to test that case!

you can try like this, if isn't work, I will make a couple of tests and back to you as soon as possible!
for(var i=0;i<result.length;i++){

var rezz=result[i];

jQuery('#ff_elem410').append(jQuery('<option>',{value:rezz[1],text:rezz[0]}));

Reagrds,
Mirko

Por favor, Identificarse o Crear cuenta para unirse a la conversación.

Tiempo de carga de la página: 0.077 segundos