<form name="form1" method="post">
  <table width="400" cellspacing="0" cellpadding="0">
    <tr> 
      <td colspan="2" height="42"> 
        <div align="center">新增工作任務</div>
      </td>
    </tr>
    <tr> 
      <td width="25%">
        <div align="right">任務主題</div>
      </td>
      <td width="75%"> 
        <input type="text" name="contentname" size="35">
      </td>
    </tr>
    <tr> 
      <td width="25%"> 
        <div align="right">負責人</div>
      </td>
      <td width="75%">   
        <select name="depart" onchange="sel(form1.depart,IdArr,TextArr)">
        </select>
        <select name="userid" >
        </select>
      </td>
    </tr>
    <tr> 
      <td width="25%"> 
        <div align="right">工作主題</div>
      </td>
      <td width="75%">   
        <select name="jobid">
          <?=$option?>
        </select>
      </td>
    </tr>
    <tr> 
      <td colspan="2" height="44"> 
        <div align="center"> 
          <input type="submit" name="submit" value="保存">
          <input type="button" name="Submit2" value="離開" onclick="self.close()">
        </div>
      </td>
    </tr>
  </table>
</form>
<?
$conn=mysql_connect("localhost","root","");
mysql_select_db("job");
$R=mysql_query("select departid,departname from depart order by id");
$Num=mysql_num_rows($R);
echo "<script language=javascript>\n";
echo "form1.depart.length=$Num;\n";
echo "IdArr=new Array();\nTextArr=new Array();\n";
$i=0;
while($PArr=mysql_fetch_array($R)){
echo "IdArr[$i]='$PArr[departid]';\n";
echo "TextArr[$i]='$PArr[departname]';\n";
echo "form1.depart.options[$i].value='$PArr[departid]';\n";
echo "form1.depart.options[$i].text='$PArr[departname]';\n";
echo "IdArr[$i]=new Array();\n";
echo "TextArr[$i]=new Array();\n";
$m=0;
$SR=mysql_query("select userid,realname from user where department=$PArr[departid]");
while($SArr=mysql_fetch_array($SR)){
echo "IdArr[$i][$m]='$SArr[userid]';\n";
echo "TextArr[$i][$m]='$SArr[realname]';\n";
$m++;
}
$i++;
}
echo "</script>\n";
?>
<script language=javascript>
sel(form1.depart,IdArr,TextArr);
function sel(select,IdArray,TextArray)
{
index=select.selectedIndex;
form1.userid.length=IdArray[index].length;
for (n=0;n<IdArray[index].length;n++)
{
var op=form1.userid.options[n];
op.value=IdArray[index][n];
op.text=TextArray[index][n];
}
}
</script>