TOPIC:

problem showing a select item populated with the database 8 months 1 week ago #271723

  • Mirec's Avatar
  • Mirec
  • Offline
  • Ultimate Breezer
  • Ultimate Breezer
  • Posts: 3262
  • Karma: 2
  • Thanks: 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

Please Log in or Create an account to join the conversation.

problem showing a select item populated with the database 8 months 1 week ago #271741

  • Mirec's Avatar
  • Mirec
  • Offline
  • Ultimate Breezer
  • Ultimate Breezer
  • Posts: 3262
  • Karma: 2
  • Thanks: 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).


File Attachment:

File Name: mypck_001171.zip
File Size:11 KB


Regards,
Mirko
Attachments:

Please Log in or Create an account to join the conversation.

problem showing a select item populated with the database 8 months 1 week ago #271750

  • Topic Author
  • Sherco
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 34
  • Thanks: 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).

Please Log in or Create an account to join the conversation.

Last edit: Post by Sherco.

problem showing a select item populated with the database 8 months 1 week ago #271752

  • Mirec's Avatar
  • Mirec
  • Offline
  • Ultimate Breezer
  • Ultimate Breezer
  • Posts: 3262
  • Karma: 2
  • Thanks: 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

Please Log in or Create an account to join the conversation.

problem showing a select item populated with the database 8 months 1 week ago #271764

  • Topic Author
  • Sherco
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 34
  • Thanks: 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]

Please Log in or Create an account to join the conversation.

problem showing a select item populated with the database 8 months 1 week ago #271769

  • Mirec's Avatar
  • Mirec
  • Offline
  • Ultimate Breezer
  • Ultimate Breezer
  • Posts: 3262
  • Karma: 2
  • Thanks: 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

Please Log in or Create an account to join the conversation.

Time to create page: 0.081 seconds

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

breezingforms.eddy-vh.com

Questions et réponses sur les forums de l'AFUJ

AFUJ

Special Offer

Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!