[英]I wish to show and hide 1 or 2 drop down menus from another drop down selection
I have code that when a item is selected in a drop down menu another drop down menu appears. 我有代码,当在下拉菜单中选择一个项目时,会出现另一个下拉菜单。 However, individually it works but as soon as it involves 2 menus the code appears to conflict. 但是,它可以单独工作,但是一旦涉及2个菜单,代码就会出现冲突。 This is what I wish to do: When selecting 'Delivery', 'Time' drop down appears. 这就是我想要做的:选择“交付”时,出现“时间”下拉列表。 When selecting 'Collection', 'Number_of_parcels' drop down appears. 选择“集合”时,出现“ Number_of_parcels”下拉列表。 When selecting 'Collection_and_Delivery', both should appear. 选择“收款和付款”时,两者均应出现。
Any help would be appreciated. 任何帮助,将不胜感激。
My code is below: 我的代码如下:
function show(aval) {
if (aval == "Collection" || aval == "Collection_and_Delivery") {
hiddenDiv.style.display='inline-block';
Form.fileURL.focus();
}
else{
hiddenDiv.style.display='none';
}
}
function show(aval) {
if (aval == "Delivery" || aval == "Collection_and_Delivery") {
hiddenNo.style.display='inline-block';
Form.fileURL.focus();
}
else{
hiddenNo.style.display='none';
}
}
</script>
</head>
<body>
<form name="form1" id="ff" method="post" action="http://www.xxxxxx.com/cgi-bin/form10.pl" onsubmit="myButton.disabled = true; return true;" target="_blank">
<table>
<tr>
<th align="left" colspan="3"> <select name="Collection_Delivery" id="Collection_Delivery" onchange="java_script_:show(this.options[this.selectedIndex].value)">
<option value="">-</option>
<option value="Delivery">Delivery</option>
<option value="Collection">Collection</option>
<option value="Collection_and_Delivery">Collection & Delivery</option>
</select>
<div id="hiddenDiv" style="display:none">
<select name="Number_of_parcels" id="Number_of_parcels">
<option value="z" selected="selected">No. of Parcels</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
</div>
<div id="hiddenNo" style="display:none">
<select name="Time" id="Time" onChange="selection()">
<option value="x" selected="selected">Time</option>
<option value="24hours">24 Hours</option>
<option value="Next_day_9am">Next Day 9am</option>
</select>
</div>
</th>
</tr>
</table>
</body>
You are re-writting the show function declaring other show function. 您正在重新编写show函数,以声明其他show函数。
I fixed the code and I did this: 我修复了代码,然后这样做:
function show(aval) {
var showCollection = (aval === "Collection"|| aval === "Collection_and_Delivery");
var showDelivery = (aval === "Delivery"|| aval === "Collection_and_Delivery");
hiddenDiv.style.display= showCollection ? "inline-block" : "none";
hiddenNo.style.display= showDelivery ? "inline-block" : "none";
//Form.fileURL.focus();
}
I recommend you these links, if you want to start learning javascript: 如果您想开始学习javascript,建议您使用以下链接:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.