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. This is what I wish to do: When selecting 'Delivery', 'Time' drop down appears. When selecting 'Collection', 'Number_of_parcels' drop down appears. 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.
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:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.