ChronoEngine.com homepage

Forums

Please write a review for the extension you are using on the Joomla extensions directory before posting a new question as we are being spammed by many negative reviews.

Thank you for your support!

Linked dropdowns

A
awgcas posted Nov 18, 2023 at 17:26
Hi, I have 2 dropdowns, with same values read from a db table. When I select an option from the first one, I should like to have the same option disabled (or removed) in the second dropdown.
I tried something like this:

$('select[name=first]').on('change', function() {
var self = this;
$('select[name=second]').find('option').prop('disabled', function() {
return this.value == self.value
});
});

where first and second are names of dropdowns, but it doesn't work ...
Any suggestion?
Thank you
Alex
Max_admin posted Nov 19, 2023 at 00:30
this code uses jQuery but v8 does not use jQuery, so unless your page has jQuery loaded then it will not work, you can check the browser's console for errors
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
A
awgcas posted Nov 19, 2023 at 08:54
Hi Max, to load jquery I have a php action including:
use Joomla\CMS\Factory;
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
$wa->useScript('jquery');

In the console I have no errors.

Thank you
Alex
Max_admin posted Nov 19, 2023 at 13:32
ok, does the change event fire in your code ? I think your code should be inside a document ready event for it to work
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
A
awgcas posted Nov 20, 2023 at 13:23
Thank you Max, now it (partially) works.

I'm using this code:
var $dropdown1 = $("select[name='first']");
var $dropdown2 = $("select[name='second']");

$dropdown1.change(function() {
    $dropdown2.empty().append($dropdown1.find('option').clone());
    var selectedItem = $(this).val();
    if (selectedItem) {
        $dropdown2.find('option[value="' + selectedItem + '"]').remove();
    }
});

because in my opinion remove option is better than disabling.

The problem now is that the option is correctly removed "from the code" (as I can see in firefox dev tools), but it is still visible in the dropdown, because it is read from the database (I guess).

I'm not a developer, but if I'm not wrong I have to remove that option from the array of vars, so it won't appear in the dropdown...

Thanks again
Alex
Max_admin posted Nov 20, 2023 at 13:46
what happens when the user "unselects" an option from the first one ? will this readd the option to 2nd one ?

I think that you better use 2 radio groups or checkboxes groups, that will be easier to "hide" and show
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
A
awgcas posted Nov 20, 2023 at 14:59
Most probably the options in the dropdown will be more that 10 , that's why I prefer it.
I made more tests: even deleting "Dynamic options" in the dropdown behavior, and creating static options, the option is still correctly removed "from the code", but visible in the dropdown; so the problem is not depending from the dynamic creation of options.

If you want, the form is available on http://131.114.28.116/index.php/test, with debug activated.
One more question: in the Vars block after submit, I have the following array (result of a read data action):
[read_data9] => Array
        (
            [0] => Array
                (
                    [id] => 1
                    [partenza] => Posto 1
                    [arrivo] => Posto 2
                    [costo] => 12
                )

        )

How can I echo via php (or html) the [costo] row?

Thank you
You need to login to be able to post a reply.

2Checkout.com

2CheckOut.com Inc. (Ohio, USA) is an authorized retailer for goods and services provided by ChronoEngine.com