获取响应<select>并以表单</select>显示

时间:2013-09-04 05:56:44

标签: php javascript html

我有一份表格,其中列有印度国家和城市名单。选择其中一个州后,该州的城市将显示在<select>中以显示城市。我正在使用某个地方托管的PHP脚本(一个类似的网站),我认为它可以解决我的目的。该脚本将<{>>州 value的{​​{1}}作为参数,并返回带有相应城市的options

脚本为<select>,其中http://www.indane.co.in/state.php?stateid=2196是所选州的ID /值。

我需要在我的城市中显示这个内容。

请建议我怎么做。

到目前为止,我已尝试过这个,

2196

1 个答案:

答案 0 :(得分:1)

问题1 - 问题是城市下拉列表的网址是返回一个选择框,而您正在用另一个选择框替换页面中选择框的选项

另一个问题是access-control-allow-origin header。

使用以下

替换页面中的城市下拉列表
       <span id="bgcity">
      <select name="bgcity" style="width:200px" >
         <option value="">[SELECT CITY]</option>
        </select>  
       </span> 

将showcat更改为

function showcat(id,ss,type)
{
   var cid=id.value;
   if(type=='state')
   {
        document.getElementById("state_loading").style.visibility="visible";
        var response = httpGet("http://www.indane.co.in/state.php?stateid="+cid);
         if(response !== undefined)
        {
           var id=document.getElementById('bgcity');
           id.innerHTML=response;
        }
    }
}

我已将与选择框关联的id移除到span,以便它替换整个下拉菜单...并删除showcat函数中的第二个参数,因为此更改将给出错误...