<!--用JSP开发时遇到的一个JavaScript问题,把如下代码全部复制到一个html页面上便看到效果--> <!--怎样用select控制文本框即时更新???-->    <script type="text/javascript"> 
  function popupinput(select) 
  { 
   var option_value = document.f1.select.options[select.selectedIndex].value; 
   var option_text = document.f1.select.options[select.selectedIndex].text; 
   //此变量用来接收 弹出文本框里的值 
   //var take_over_username_value = document.f1.take_over_username.value; 
      
   if(option_value==1) 
   { 
   take_over_username_value = "toall"; 
   alert("take_over_username_value: "+take_over_username_value);    
   document.f1.take_over_username.style.display="none"; 
   } 
   if(option_value==2) 
   { 
   
   take_over_username_value="single";   //此时数值已经改过来了,但是文本框没有即时更新,请各位朋友帮帮忙!谢谢啦 
   alert("take_over_username_value: "+take_over_username_value); 
   document.f1.take_over_username.style.display="block"; 
   } 
  } 
   
  function test() 
  { 
   var take_over_username_value = document.f1.take_over_username.value; 
   alert(take_over_username_value); 
  } 
   </script> 
   </head> 
   
   <body>   
   <form action="Send_message.jsp" method="get" name="f1" onsubmit="test()"> 
   <table border=1>   
   <tr> 
   <td>接收人: </td> 
   <td id="t01"> 
   <select name="select" onChange="popupinput(select)"> 
   <option selected value="1">所有人 </option> 
   <option value="2">单人或多人 </option> 
   </select> 
   <input type="text" id="t01" name="take_over_username" style="display:none" value="toall" size="30"> 
   </td> 
   </tr> 
   <tr> 
   <td>标题: </td> 
   <td> <input type="text" name="title"> </td>      
   </tr>   
   <tr> 
   <td valign="top">信息内容: </td> 
   <td> 
   <textarea cols="20" rows="10" name="content"> 
   </textarea> 
   </td> 
   </tr>   
   <tr> 
   <td> <input type="submit" value="提交"> </td> 
   <td> <input type="reset" value="重置"> </td>      
   </tr>      
   </table> 
   </form> 
   </body> 
   
   
<!-- 
以下是我搜索出来的即时更新文本框的用法,可这是用文本框更新文本框的,而我需要用select即时更新文本框,那应该怎样改呢? 
<script>    
  function   changeIt()    
  {    
  if(document.all("txt1").value   ==   "")    
  {    
      document.all("txt2").value   =   "";    
      return;    
  }       
  document.all("txt2").value   =   parseInt(document.all("txt1").value)   ;    
  }    
</script>   
   
<form id=form1 action="" >    
   <input   type=text   id=txt1   onkeyup="changeIt()">    
   <input   type=text   id=txt2>    
</form>     
-->

解决方案 »

  1.   

    take_over_username_value="single";   //此时数值已经改过来了,但是文本框没有即时更新,请各位朋友帮帮忙!谢谢啦  
    改成
    document.f1.take_over_username.value ="single";   
      

  2.   

    修正一下
    take_over_username_value="single";   //此时数值已经改过来了,但是文本框没有即时更新,请各位朋友帮帮忙!谢谢啦   
    后加
    document.f1.take_over_username.value ="single";   
      

  3.   

    take_over_username_value="single";   //此时数值已经改过来了,但是文本框没有即时更新,请各位朋友帮帮忙!谢谢啦  
       alert("take_over_username_value: "+take_over_username_value);  
       document.f1.take_over_username.style.display="block"; 
    document.f1.take_over_username.value= "single";