提交表单时,为什么选择框不会附加?

时间:2014-08-06 15:24:09

标签: javascript php html

我使用javascript填充选择框。选择其他商店名称后,它将更改回默认值。代码如下:

var selected_store = "<?php if (!empty($_POST['store'])) { echo $_POST['store']; } else { echo "-1"; } ?>";    function loadStores() {
    $('#store').html('<option value="-1">Store Name</option>');
            for (var i = 0; i < stores.length; i++) {
            console.log(selected_store);
                console.log(stores[i]);
                if (stores[i] == selected_store) {
                            $('#store').append('<option value="'+stores[i]+'" selected>'+stores[i]+'</option>');
                } else {
                    $('#store').append('<option value="'+stores[i]+'">'+stores[i]+'</option>');
                } 
            }
        } </script>      <div id="form">
<form method='post'>
        <select>
            <option>Loan Type</option>
            <option>Payday</option>
            <option>Title</option>
        </select>
        <select>
            <option>District Manager</option>
        </select>
        <select id="store" >
            <option value="-1">Store Name</option>
        </select>
        <input type="submit" class='chart_button' name="submit" id="chart_button" value="Get Data" />
</form>

selected_store始终返回-1,即使选择了不同的商店也是如此。

0 个答案:

没有答案