<html>
<head>
<title></title>
<script>
select2str=function(id)
{
var obj=document.getElementById(id);
var destobj=document.getElementById(id.replace("sel_",""));
var strValue="";
for( var i=0; i<obj.options.length; i++)
{
if( obj.options[i].selected)
{
strValue+=obj.options[i].value+",";
}
}
strValue=strValue.substring(0,strValue.lastIndexOf(','));
destobj.value=strValue;
alert(strValue);
}
bindselect=function(id,strvalue)
{
var obj=document.getElementById(id);
var strs=strvalue.split(",");
for( var i=0; i<obj.options.length; i++)
{
if( isinarray(obj.options[i].value,strs))
{
obj.options[i].selected=true;
}
}
}
isinarray=function(value,arr)
{
for(var i=0; i<arr.length; i++)
{
if(value==arr[i])
{
return true;
}
}
return false;
}
</script>
</head>
<body>
<select id="sel_cate" size="3" multiple >
<option value="1">x1</option>
<option value="2">x2</option>
<option value="3">x3</option>
<option value="4">x4</option>
</select>
<script>
bindselect('sel_cate','1,4');
</script>
<input type="text" id="cate" name="cate" />
<input type="button" id="btnSure" name="btnSure" οnclick="select2str('sel_cate')" />
</body>
</html>