动态显示codeigniter中选择列表下拉列表中的选定值

时间:2015-04-10 16:30:05

标签: ajax codeigniter

我使用Ajax请求和Select Box在我的应用程序中为Country州城创建了一个Cascading of Dropdown列表。我的应用程序收集有关用户的信息,即个人信息等。在我的应用程序中,有一个选项可以编辑输入的字段..单击编辑按钮后,个人信息页面将填充先前输入的数据。现在我需要帮助来显示所选值,即用户在我的选择框下拉列表中选择了哪个国家/地区,州和城市。请帮忙!!

1 个答案:

答案 0 :(得分:0)

在您的视图中,将之前选择的值指定给javascript var。然后,当ajax请求成功时,从var。

设置下拉值

这是使用jQuery的一个例子。

// set a js var from a php var passed to the view from CI
var previous_country = <?=$previous_country?>;

$.ajax({
    // your ajax options here (url, datatype, etc)
    success: function(response){
        // code to populate dropdown here
        // then set the dropdown value to change the selected item:
        $('select#country').val(previous_country);
    }
});
相关问题