×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

hehe, so simple a question, this is the real sample, u have to use style.visibility to hide or show the TextBox

<html>

<script type="text/javascript">
function change()
{
x=document.all.DropDownList1.value;
if(x=="x4")
eval("document.all.Text1.style.visibility='hidden';");
else
eval("document.all.Text1.style.visibility='visible';");
}
</script>

<body>
<form name="form1" method="post" id="form1">
<select name="DropDownList1" id="DropDownList1" onchange="change()">
<option value="x1">x1</option>
<option value="x2">x2</option>
<option value="x3">x3</option>
<option value="x4">x4</option>
</select>

<input id="Text1" type="text" value="cctv"/>
</form1>
</body>
</html>
Report

Replies, comments and Discussions:

  • 工作学习 / 专业技术讨论 / 想依据SELECT的不同选项,决定是否显示接下来的TEXT INPUT对象,哪位大侠知道如何做?
    • use JavaScript
      • Thanks, but I want to known "how to" code it using Javascript
    • sample code inside
      <form name="myform">
      <SELECT NAME="myselect">
      <OPTION VALUE="valueA" selected>ABCD
      <OPTION VALUE="valueB">EFGH
      </SELECT>
      </form>


      inside javascript function:

      var value = document.myform.myselect.value;
      if(value == "valueA"){...}
      else {...}
    • hehe, so simple a question, this is the real sample, u have to use style.visibility to hide or show the TextBox
      <html>

      <script type="text/javascript">
      function change()
      {
      x=document.all.DropDownList1.value;
      if(x=="x4")
      eval("document.all.Text1.style.visibility='hidden';");
      else
      eval("document.all.Text1.style.visibility='visible';");
      }
      </script>

      <body>
      <form name="form1" method="post" id="form1">
      <select name="DropDownList1" id="DropDownList1" onchange="change()">
      <option value="x1">x1</option>
      <option value="x2">x2</option>
      <option value="x3">x3</option>
      <option value="x4">x4</option>
      </select>

      <input id="Text1" type="text" value="cctv"/>
      </form1>
      </body>
      </html>
      • Copy the all codes to a HTML file, use IE to run it, if u select "X4" , TextBox will be hidden, otherwise TextBox will be showen, good luck
        • Just a little tip, this forum supports html code :)
          • oh well, maybe not for the JS codes. sry :p
          • 是吗?我试试
        • 一个问题,这个SAMPLE可以隐藏INPUT,但是如何隐藏INPUT前面的文本提示呢?
    • 多谢上面两位大虾,It works. binghongcha76的SAMPLE可直接使用。
      <html>
      <body>
      <form name="myform">
      <SELECT NAME="myselect" onchange="javascript:change();">
      <OPTION VALUE="valueA" selected>ABCD
      <OPTION VALUE="valueB">EFGH
      </SELECT>
      </form>


      <script language="javascript">
      function change()
      {
      var value = document.myform.myselect.value;
      if(value == "valueA"){alert("test");}
      else {alert("test1");}
      }
      change();
      </script>
      </body>
      </html>