How to change select list from another using AJAX in Joomla

后端 未结 1 1013
陌清茗
陌清茗 2021-01-06 05:28

I have a list of countries and a list of cities for each country. I set both as drop-down list.

My problem is how can I change the cities listed when the selected co

相关标签:
1条回答
  • 2021-01-06 05:29

    A note appart, you're using the deprecated JRequest::getInt(); where you should be using

    $input = JFactory::getApplication()->input;
    $country_id = $input->getInt('country_id', 0);
    

    In order to change the second select, you must trigger the update of the second select:

    $(".country").change(function(){
        // your ajax call from your code
    
        // on success, you need to trigger the second select by using
        $( ".city_id" ).val(your_value_from_ajax_response).trigger( "liszt:updated" );
    
    });
    
    0 讨论(0)
提交回复
热议问题