- 爱易网页
-
JavaSript
- select下拉列表选项赋值的有关问题
日期:2014-05-16 浏览次数:20383 次
select下拉列表选项赋值的问题
我从数据库中读出“人数”和“部门”,希望在下拉列表中显示的是“部门”的名字以供选择。传递回来的值部分,必须含有“人数”,“部门”两个部分。原因为:“部门”作为提交后传递给下个页面,“人数”的值直接传递给本页面另一个文本框为默认值,以提供计算。
如上,我希望将“部门”“人数”作为一个数组,赋值给option的value。不知道js要怎么赋值。另外,那个文本框如何获得该“人数”值?
<select name= "deb_in_line_slt[] " id= "deb_in_line_slt "
onchange= "deb_in_quan.value=this[0].value;deb_in_totl.value=(deb_in_quan.value)*(deb_in_time_slt.value) ">
请高人指教一二。
------解决方案--------------------
<html>
<head>
<SCRIPT>
function procData()
{
var op = document.form1.deb_in_line_slt.options;
for (var i = 0; i < op.length; i++)
{
if (op[i].selected)
{
document.form1.deb_in_quan.value = op[i].text + "& " + op[i].value;
}
}
return true;
}
</SCRIPT>
</head>
<body onload= " ">
<form name= "form1 " method= "post " action= "deb_addi_chek.php " onsubmit= "return procData() ">
<table width= "99% " border= "0 ">
<tr>
<td width= "3% "> </td>
<td width= "97% ">
<table width= "88% " border= "0 " align= "left ">
<tr>
<td height= "28 " width= "16% "> 部门选择: </td>
<td height= "28 " width= "32% "> <select name= "deb_in_line_slt " id= "deb_in_line_slt "
onchange= "deb_in_quan.value=this.value;deb_in_totl.value=(deb_in_quan.value)*(deb_in_time_slt.value) ">
<option value= " "> 请选择部门 </option>
<option value= "10 "> 人事 </option>
<option value= "20 "> 业务 </option>
<option value= "30 "> 品保 </option>
</select>
</td>
<td height= "28 " width= "20% " align= "right "> 该部人数: </td>
<td height= "28 " width= "32% " align= "left ">
<input name= "deb_in_quan " type= "text " id= "deb_in_quan " size= "6 " readonly>
</td>
</tr>
<tr>
<td height= "28 "> 调休时数: </td>
<td height= "28 "> <select name= "deb_in_time_slt " id= "deb_in_time_slt "
onchange= "deb_in_totl.value=(deb_in_quan.value)*(this.value) ">
<option value= " "> 请选择时数 </option>
<option value= "1 "> 1 </option>
<option value= "2 "> 2 </option>
<option value= "3 "> 3 </option>
</select> </td>
<td height= "28 " align= "right "> 总 时 数: </td>
<td height= "28 " align= "left ">
<input name= "deb_in_totl " type= "text " size= "6 " readonly> </td>
</tr>
<tr>
<td colspan= "4 " height= "56 ">