如何禁用其他下拉菜单

时间:2019-10-08 13:14:14

标签: javascript php html

我要禁用“省”,“城市”和“ Barangay”。当我单击“区域”时,应启用“省”。当我在“省”中选择一个选项时,应启用“城市”,依此类推。

    function dynamicdropdownProvince(listindex)
	{
		switch (listindex) {
		case "metromanila" :
			document.getElementById('provincestatus').options[0]=new Option("Province","");
			document.getElementById("provincestatus").options[1]=new Option("Metro Manila","metromanila");
			break;   
		case "mindanao" :
			document.getElementById("provincestatus").options[0]=new Option("Province","");
			document.getElementById("provincestatus").options[1]=new Option("Agusan Del Norte","agusandelnorte");
			break;
		}
		return true;
	}

	function dynamicdropdownCity(listindex)
	{
		switch (listindex) {
		  case "agusandelnorte" :
			document.getElementById("citystatus").options[0]=new Option("City","");
			document.getElementById("citystatus").options[1]=new Option("Buenavista","buenavista");
			break;
		  case "metromanila" :
			document.getElementById("citystatus").options[0]=new Option("City","");
			document.getElementById("citystatus").options[1]=new Option("Binondo","binondo");
			break;
		}
		return true;
	}

	function dynamicdropdownBarangay(listindex)
	{
		switch (listindex) {
		case "buenavista" :
		  document.getElementById("barangaystatus").options[0]=new Option("Barangay","barangaystatus");
		  document.getElementById("barangaystatus").options[1]=new Option("Alubijid","alubijid");
		  break;
		case "binondo" :
		  document.getElementById("barangaystatus").options[0]=new Option("Barangay","barangaystatus");
		  document.getElementById("barangaystatus").options[1]=new Option("Barangay 287","barangay287");
		  break;
		}
		return true;
    }
<div>
<input class="input-field" name="postal" type="text" placeholder="Postal Code" name="postal" required>  
	<select class="input-field" name="region" id="region" onclick="makeDisable()" onchange="javascript: dynamicdropdownProvince(this.options[this.selectedIndex].value);">
		<option disabled selected>Region</option> 
		<option value="metromanila">Metro Manila</option>
		<option value="mindanao">Mindanao</option>
		<option value="northluzon">North Luzon</option>
		<option value="southluzon">South Luzon</option>
		<option value="visayas">Visayas</option> 
	</select>

	<script type="text/javascript" language="JavaScript">
		document.write('<select class="input-field" onchange="javascript: dynamicdropdownCity(this.options[this.selectedIndex].value);" name="provincestatus," id="provincestatus"><option value="">Province</option></select>')
		document.write('<select class="input-field" onchange="javascript: dynamicdropdownBarangay(this.options[this.selectedIndex].value);" name="citystatus" id="citystatus"><option value="">City</option></select>')
		document.write('<select class="input-field" name="barangaystatus" id="barangaystatus"><option value="" >Barangay</option></select>')
	</script>
	</div>

1 个答案:

答案 0 :(得分:1)

您必须使用元素的RetryOperationsInterceptor属性

disabled
    document.write('<select class="input-field" onchange="javascript: dynamicdropdownCity(this.options[this.selectedIndex].value);" name="provincestatus" id="provincestatus" disabled><option value="">Province</option></select>')
    document.write('<select class="input-field" onchange="javascript: dynamicdropdownBarangay(this.options[this.selectedIndex].value);" name="citystatus" id="citystatus" disabled><option value="">City</option></select>')
    document.write('<select class="input-field" name="barangaystatus" id="barangaystatus" disabled><option value="" >Barangay</option></select>')


function dynamicdropdownProvince(listindex)
{
    switch (listindex)
    {
    case "metromanila" :
        document.getElementById('provincestatus').options[0]=new Option("Province","");
        document.getElementById("provincestatus").options[1]=new Option("Metro Manila","metromanila");
        document.getElementById("provincestatus").disabled=false;
        break;   
    case "mindanao" :
        document.getElementById("provincestatus").options[0]=new Option("Province","");
        document.getElementById("provincestatus").options[1]=new Option("Agusan Del Norte","agusandelnorte");
        document.getElementById("provincestatus").disabled=false;
        break;
    }
    return true;
}
function dynamicdropdownCity(listindex)
{
    switch (listindex)
    {
      case "agusandelnorte" :
        document.getElementById("citystatus").options[0]=new Option("City","");
        document.getElementById("citystatus").options[1]=new Option("Buenavista","buenavista");
        document.getElementById("citystatus").disabled=false;
        break;
      case "metromanila" :
        document.getElementById("citystatus").options[0]=new Option("City","");
        document.getElementById("citystatus").options[1]=new Option("Binondo","binondo");
        document.getElementById("citystatus").disabled=false;
        break;
    }
    return true;
}
function dynamicdropdownBarangay(listindex)
{
    switch (listindex)
    {
    case "buenavista" :
      document.getElementById("barangaystatus").options[0]=new Option("Barangay","barangaystatus");
      document.getElementById("barangaystatus").options[1]=new Option("Alubijid","alubijid");
      document.getElementById("barangaystatus").disabled=false;
      break;
    case "binondo" :
      document.getElementById("barangaystatus").options[0]=new Option("Barangay","barangaystatus");
      document.getElementById("barangaystatus").options[1]=new Option("Barangay 287","barangay287");
      document.getElementById("barangaystatus").disabled=false;
      break;
    }

    return true;
}