选择第三项下拉列表时,应显示输入框

时间:2014-02-12 07:16:40

标签: php

你好我有一个链式下拉,第一个由三个项目组成,而选择第一个,第二个下拉将显示它的项目,就像第二个选项一样。

第三个是属性ID我的意思是每当我选择这个时,禁用的输入框应该是可见的,否则它应该被隐藏。

有人请吗?

这是我的代码:

    <!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>Search Area</title>

<script language="javascript" type="text/javascript">
function setOptions(chosen) {
var selbox = document.myform.status;

selbox.options.length = 0;
if (chosen == " ") 
{
  selbox.options[selbox.options.length] = new Option('Please Select one',' ');

}
if (chosen == "1") 
{
  selbox.options[selbox.options.length] = new Option('Please Select One');
  selbox.options[selbox.options.length] = new Option('For Rent');
  selbox.options[selbox.options.length] = new Option('For Sale');
  selbox.options[selbox.options.length] = new Option('For Lease');
}
if (chosen == "2") 
{
  selbox.options[selbox.options.length] = new Option('Please Select One');
  selbox.options[selbox.options.length] = new Option('Approved');
  selbox.options[selbox.options.length] = new Option('Pending');
}
if (chosen == "3") 
{
   document.getElementById("propertyid").style.visibility= visibile;
}

}


</script>

</head>

<body>
<form name="myform">

    <select name="dealtype" class="select" size="1" onchange= "setOptions(document.myform.dealtype.options[document.myform.dealtype.selectedIndex].value);">

<option value=" " selected="selected">Select Please One</option>
          <option value="1">Property Deal Type</option>
          <option value="2">Property Status </option>
          <option value="3">Property ID</option>
</select>


  <select name="status" size="1">
  <option value=" " selected="selected">Select Please One</option>        
  </select>
 <input type="text" onchange= "setOptions(document.myform.dealtype.options[document.myform.dealtype.selectedIndex].value);" name="search" id="propertyid" style="visibility:hidden"/>


</form> 

</body>
</html>

1 个答案:

答案 0 :(得分:0)

需要简化您的选择框  像这样

<select name="dealtype" class="select" size="1" onchange= "setOptions(this.value);">

<option value=" " selected="selected">Select Please One</option>
          <option value="1">Property Deal Type</option>
          <option value="2">Property Status </option>
          <option value="3"Property ID</option>
</select>

你的js函数应该是

<script language="javascript" type="text/javascript">
function setOptions(chosen) {
var selbox = document.myform.status;

selbox.options.length = 0;
if (chosen == " ") 
{
  selbox.options[selbox.options.length] = new Option('Please Select one',' ');

}
else if (chosen == "1") 
{
  selbox.options[selbox.options.length] = new Option('Please Select One');
  selbox.options[selbox.options.length] = new Option('For Rent');
  selbox.options[selbox.options.length] = new Option('For Sale');
  selbox.options[selbox.options.length] = new Option('For Lease');
}
else if (chosen == "2") 
{
  selbox.options[selbox.options.length] = new Option('Please Select One');
  selbox.options[selbox.options.length] = new Option('Approved');
  selbox.options[selbox.options.length] = new Option('Pending');
}
else if (chosen == "3") 
{
   document.getElementById("propertyid").style.display = 'block';
}

}



</script>

并且隐藏的文本框应该与ID propertyid

一样

<input type="text" name="search" id="propertyid" style="display:none"/>