|
发表于 2007-7-13 13:53:36
|
显示全部楼层
不用JS是不可能的,总不能选一个刷一下页面吧,我用xajax解决的
function myResponse()
{
$objResponse =& new legacyXajaxResponse();
$objResponse->setCharEncoding("gb2312");
return $objResponse;
}
function html_options($arr, $set='AaBa005353dffs')
{
foreach($arr as $k=>$v)
{
if(is_array($v))
{
$options[] = "<optgroup title='$k'>";
foreach($v as $k2=>$v2)
{
$selected = ($set == $k)?'selected':'';
if(is_array($set))$selected = (in_array($k, $set))?'selected':'';
$options[] = "<option value='$k2' $selected>$v2</option>";
}
$options[] = "</optgroup>";
}
else
{
$selected = ($set == $k)?'selected':'';
if(is_array($set))$selected = (in_array($k, $set))?'selected':'';
$options[] = "<option value='$k' $selected>$v</option>";
}
}
return implode("\n", $options);
}
function html_select($idname='select', $options='', $set='AaBa00fte6t5', $js='', $size=0)
{
$size = ($size==0)?'':"size='$size'";
$select = "<select name='$idname' id='$idname' $size $js>\n";
if(is_array($options))$select .= html_options($options, $set);
$select .= "</select>\n";
return $select;
}
function ProvinceSelect($name='province', $cityname='city', $set='上海', $label='id_province', $id_city='id_city')
{
global $db;
$objResponse = myResponse();
$sql = "select value,id from province where countrycode='86' order by value";
$rs = $db->query($sql);
while($row = $db->fetch($rs))
{
$province[$row[0]] = $row[0];
}
$objResponse->addassign($label, "innerHTML", html_select($name, $province, $set, "onchange=\"xajax_CitySelect('$cityname', this.options[this.selectedIndex].value, '', '$id_city')\""));
return $objResponse;
}
function CitySelect($name='city', $province='上海', $set='上海', $label='id_city')
{
global $db;
$objResponse = myResponse();
$sql = "select id from province where value='$province'";
$rs = $db->query($sql);
$row = $db->fetch($rs);
$provinceid=$row[0];
$sql = "select value from city where province_id='$provinceid'";
$rs = $db->query($sql);
$city['不限'] = '不限';
while($row = $db->fetch($rs))
{
$city[$row[0]] = $row[0];
}
$objResponse->addassign($label, "innerHTML", html_select($name, $city, $set));
return $objResponse;
} |
|