在选择第一个选择框值后填充第二个选择框

时间:2015-09-11 05:26:28

标签: php jquery codeigniter

我只需在选择第一个选择框后选择第二个选择框值。我想将这些值插入数据库..我的视图页面如下。

<div class="form-group">
                <label for="" class="control-label col-xs-2">Country</label>
                <div class="col-md-6">
                    <select class="form-control" id="edu" onChange="EduBackgrd()" name="country">
                        <option value="">Select</option> 
                        <option value='India'>India</option>
                        <option value='United States'>United States</option>
                        <option value='United Kingdom'>United Kingdom</option>
                        <option value='Canada'>Canada</option>
                        <option value='Singapore'>Singapore</option>
                        <option value='Others'>Others</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label for="" class="control-label col-xs-2">Location</label>
                <div class="col-md-6">
                    <select class="form-control" id="edct" name="location">
                    <option value="">Select</option>

                    <script>
    var eduBak = {};
    eduBak['India'] = ['Delhi', 'Mumbai', 'Chennai', 'Kolkata', 'Bangalore', 'Hyderabade', 'Pune'];
    eduBak['United States'] = ['Alabama', 'Alaska', 'Arizona'];
    eduBak['United Kingdom'] = ['England', 'Northrn Ireland', 'Scotland', 'Wales', 'other'];
    eduBak['Canada'] = ['Alberta ', 'Brirish Columbia', 'Manitoba', 'others'];
    eduBak['Singapore'] = ['Singapore','others'];
    eduBak['Others'] = ['Others']

    function EduBackgrd() {
        var edu = document.getElementById("edu");
        var model = document.getElementById("edct");
        var educ = edu.options[edu.selectedIndex].value;
        while (model.options.length) {
            model.remove(0);
        }
        var ed = eduBak[educ];
        if (ed) {
            var i;
            for (i = 0; i < ed.length; i++) {
                var e = new Option(ed[i], i);
                model.options.add(e);
            }
        }
    } 
    </script>
</select>
                </div>
            </div>

要插入数据库,我尝试了我的模型:

public function insert()
{
$data=array(
'Country'=>$this->input->post('country'),
        'Location'=>$this->input->post('location'),
        );
$this->db->insert('tbl_employer', $data);
        }

我在插入时得到一个数字..我不知道如何在我为选择第二个选择框而编写的脚本中设置值属性。我该如何解决这个问题?

0 个答案:

没有答案
相关问题