[英]How to display a div when values are selected from TWO dropdown?
Here I have two dropdown 在这里我有两个下拉菜单
<div class="form-group">
<label class="col-sm-4 control-label">Car Type</label>
<div class="col-sm-7">
<select class="form-control" id="cartype" name="cartype">
<option value=""> -- Select Type -- </option>
<option value="Innova">Innova</option>
<option value="Tata">Tata</option>
<option value="Mahindra">Mahindra</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">Rate Type</label>
<div class="col-sm-7">
<select class="form-control" id="rate" name="rate" onchange="showdiv()" >
<option value=""> -- Select Type -- </option>
<option value="Outstation" name="outstation" id="outstation">Outstation</option>
<option value="Local" name="local" id="local">Local</option>
</select>
</div>
And a Text Box 还有一个文本框
<div class="form-group" id="showme" style="display:none;">
<input type="text" id="txt1" name="txt1">
</div>
My Javascript 我的Javascript
function showdiv(){
var vehicle = document.getElementById("cartype").value = "Innova || Tata";
var rate = document.getElementById("rate").value = "Local";
document.getElementById("showme").style.display = 'block';
}
Here I need to display the Text Box div
only when cartype is equal to Local
. 在这里,仅当cartype等于
Local
时,才需要显示Text Box div
。 But when I select Rate Type
the hidden div
is displaying. 但是,当我选择
Rate Type
将显示隐藏的div
。
Can you help me out where is the error in my code?? 您能帮我解决我的代码中的错误吗?
this should be working: 这应该工作:
function showdiv(){
var vehicle = document.getElementById("cartype").value;
var rate = document.getElementById("rate").value;
if ((vehicle == "Innova" || vehicle == "Tata") && rate == 'Local') {
document.getElementById("showme").style.display = 'block';
} else {
document.getElementById("showme").style.display = 'none';
}
}
Try this 尝试这个
function showdiv(){
if((document.getElementById("cartype").value == "Innova" || document.getElementById("cartype").value == "Tata") && (document.getElementById("rate").value == "Local")){
document.getElementById("showme").style.display = 'block';
} else {
document.getElementById("showme").style.display = 'none';
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.