JS部分——自己瞎写的。。
<script language="javaScript">
 function officecode()
{
    //获取officename/officecode的值
  var officename = document.form4.officename.value;
  var officecode = document.form4.officecode.value;
   //条件判断
     if (officename == "语文办公室"){
     document.form4.officecode.value=="0001";
   }
   else if(officename ==  "数学办公室" ){
    document.form4.officecode.value=="0002";
   }
   else{
    return false;
   }
}
</script>HTML部分
<form name="form4" id="form4" action="new.php" method="post">
<table width="200" border="1">
  <tr>
    <td width="80px;">办公室号码</td>
    <td><input type="text" name="officecode" style="width:100px;"  /></td>
  </tr>
  <tr>
    <td width="100px;">办公室名称</td>
    <td>
    <select name="officename" id="officename">
    <option value="语文办公室" selected>语文办公室</option>
    <option value="数学办公室">数学办公室</option>
    </select>
    </td>
  </tr>
</table>
<input type="button" value="确定" onclick="return officecode();">
其他PHP内容,省略实现目标,
通过选择好,相应的办公室,生成对应的办公号码——最好能够实时生成
JS我只看过注册用户时的一些相关内容,就是对于非空、数量之类的限制判断,但这个我不太清楚应该如何去搜索。
请大家帮忙下,谢谢又尝试用jquery 用百度的示例模仿
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
</head>
<script language="javascript" type="text/javascript">
$(document).ready(function(){$("ck").click(function(){  //点击按钮事件
  if($("#name").value=="libin"){
      $("#ct").val("001");
 };
 
 else if($("#name").value=="lisi"){
        $("#ct").val("002");
 };
 
});
 
 $("#txt").val("2");  //试验用,证明jquery插入正确
 
});
</script>
<body>
<!--<div id="ct" style="z-index:1000">显示hidden值</div>
<input  type="text" name="issueType" value="55555555" id="issueType"/>--><select name="name" id="name" />
<option value="libin">libin</option>
<option value="lisi">lisi</option>
</select>
<input type="text" id="ct" name="ct" />
<input type="text" id="txt" name="txt" />
<input type="button" id="ck" name="ck" value="确认" /></body>
</html>
点击按钮没有反应
txt的值能正确取到另外,补充问题,能不能利用JS/JQUERY让我选择了<select>的内容后,后面记录号码的<input>文本框自动就好?谢谢

解决方案 »

  1.   

    <table width="200" border="1">
      <tr>
        <td width="80px;">办公室号码</td>
        <td><input type="text" id="officecode" style="width:100px;"  /></td>
      </tr>
      <tr>
        <td width="100px;">办公室名称</td>
        <td>
        <select name="officename" id="officename" onchange="setofficecode()">
        <option value="语文办公室" selected>语文办公室</option>
        <option value="数学办公室">数学办公室</option>
        </select>
        </td>
      </tr>
    </table>
    <input type="button" value="确定" onclick="return officecode();"> function setofficecode()
    {
        //获取officename/officecode的值
      var officename = document.getElementById("officename").value;
      var o = document.getElementById("officecode");
       //条件判断
     if (officename == "语文办公室"){
         o.value="0001";
       }
       if(officename ==  "数学办公室" ){
        o.value="0002";
       }
       
    }
      

  2.   

    你写错了很多地方:
    1:document.form4.officecode.value=="0001";//设置值只用“=”,不用“==”
    2:下拉框只要绑定onchange就可以实现实时的操作3:再一个你定义的函数名称与input的名称重复了,换过个名字吧4:获取输入框的值,还是建议使用:document.getElementById("输入框的ID").value;