从jcel填充的HTML javascript Dropdownlist

时间:2013-11-06 20:36:50

标签: javascript html

我要做的是使用excel文件中的值填充html下拉列表。我还需要将它编码到第一个字段中的一个下拉框中的值,然后填充另一个下拉框。

excel文件将包含我已编码到HTML中的名称列表,但此列表会更改。所以我需要一种从excel文件中提取信息的方法。第一行不会显示在HTML文件中,因为它将被编码到网页中。

Excel文件

县城 戴维森安提阿 戴维森纳什维尔 卢瑟福·士麦那

当有人从html表单中选择县戴维森时,我希望它在另一个下拉框中显示戴维森城市供他们选择。我一直用来实现这个没有excel的代码如下:

<htmL>
<title>
</title>



<body>
<script type="text/javascript">


function configureDropDownLists(county,city) {
        var Davidson = new Array('', 'Antioch', 'Nashville');
        var Rutherford = new Array('', 'Smyrna', 'LaVergne');

        switch (county.value) {
                 case 'Davidson':
                       document.getElementById(city).options.length = 0;
                       for (i = 0; i < Davidson.length; i++) {
                       createOption(document.getElementById(city), Davidson[i], Davidson[i]);
                }
                break;
            case 'Rutherford':
                document.getElementById(city).options.length = 0; 
            for (i = 0; i < Rutherford.length; i++) {
                createOption(document.getElementById(city), Rutherford[i], Rutherford[i]);
                }
                break;
        }

    }

 function createOption(county, text, value) {
        var opt = document.createElement('option');
        opt.value = value;
        opt.text = text;
        county.options.add(opt);
    }
</script>
<tr>
<td>County Name: </td>
<td><select id="county" onchange="configureDropDownLists(this,'city');">
<option value=""></option>
<option value="Davidson">Davidson</option>
<option value="Rutherford">Rutherford</option>
</select></td>
</tr><br>
<tr>
<td>City: </td>
<td><select id="city">
</select></td>
</tr>


</body>
</html>

我不确定如何从我的Excel工作表中获取数据,因为我需要搜索第一列,第二列用javascript,activeX或任何其他可以执行此操作的编码语言显示网页中的技巧。 excel文件将与同一目录中的网页一起位于共享驱动器上。

1 个答案:

答案 0 :(得分:0)

JavaScript无法访问文件系统以便能够执行此操作。最好的办法是读取服务器端的信息,并在页面加载时填充列表。如果不是页面加载并且基于用户选择,则需要AJAX进行无缝转换。

相关问题