I am looking for a solution in Javascript that would enable (place the check in it) a checkbox on a form, based upon a specific drop-down value (in standard HTML, generated by SQL) being selected elsewhere on the same form. I've not written any code yet, so don't have any to show here at this time. EDIT on 04/08/20: Based upon the excellent help received from Giuliano, I decided to add the code that I put together, (which is not working), as follows:
<%
sSQL = "SELECT OrderTypeID, OrderTypeString FROM LookupOrderTypesII"
Set rsOrderTypes = Server.CreateObject("ADODB.RecordSet")
rsOrderTypes.Open sSQL, oConnGlobal, adOpenStatic, adLockReadOnly
iTotalRecords = rsOrderTypes.Recordcount
If iTotalRecords > 0 Then
%>
<br>
<b>SERVICE/ORDER TYPE:</b>
<br>
<script type="text/javascript">
let select = document.getElementById("cboOrderType");
let checkbox = document.getElementById("chkSkipVenueEventDetails");
select.addEventListener("change", function () {
checkbox.checked = select.value == "12|LABOR SALES/PAYMENT";
});
</script>
<select class="rounded" name="cboOrderType" id="cboOrderType">
<option value="Select One" selected>Select One</option>
<option value="-9999" <%=IfSelected(iOrderTypeID, "Not Listed-ADD Custom Type")%>>Not Listed-ADD Custom Type</option>
<%
Do While Not rsOrderTypes.EOF
iOrderTypeID = Trim(rsOrderTypes("OrderTypeID"))
sOrderTypeString = Trim(rsOrderTypes("OrderTypeString"))
%>
<option value="<%=iOrderTypeID%>|<%=sOrderTypeString%>"<%=IfSelected(sOrderTypeString, sOrderTypeString_NewRequest)%>><%=sOrderTypeString%></option>
<%
rsOrderTypes.MoveNext
Loop
%>
</select>
<%
rsOrderTypes.Close
Set rsOrderTypes = Nothing
End If
%>
'''
The SQL code generates the following code (as viewed in browser source):
'''
<select class="rounded" name="cboOrderType" id="cboOrderType">
<option value="Select One" selected>Select One</option>
<option value="-9999" >Not Listed-ADD Custom Type</option>
<option value="1|WILL CALL">WILL CALL</option>
<option value="2|DELIVERY ONLY-CUSTOMER RETURN">DELIVERY ONLY-CUSTOMER RETURN</option>
<option value="3|DELIVERY and PICKUP ONLY (Dry Hire)">DELIVERY and PICKUP ONLY (Dry Hire)</option>
<option value="4|DELIVERY with SETUP and STRIKE">DELIVERY with SETUP and STRIKE</option>
<option value="5|DELIVERY with SETUP ONLY-CUSTOMER STRIKES">DELIVERY with SETUP ONLY-CUSTOMER STRIKES</option>
<option value="6|SHIPPED-CUSTOMER RETURN">SHIPPED-CUSTOMER RETURN</option>
<option value="7|SUPERVISION ONLY">SUPERVISION ONLY</option>
<option value="8|CONSULTATION SERVICES">CONSULTATION SERVICES</option>
<option value="9|EQUIPMENT SALES-WILL CALL">EQUIPMENT SALES-WILL CALL</option>
<option value="10|EQUIPMENT SALES-SHIPPED">EQUIPMENT SALES-SHIPPED</option>
<option value="11|COMMISSION SALES">COMMISSION SALES</option>
<option value="99|TEST ORDER">TEST ORDER</option>
<option value="12|LABOR SALES/PAYMENT">LABOR SALES/PAYMENT</option>
</select>
And here is the checkbox HTML:
<input type="checkbox" name="chkSkipVenueEventDetails" id="chkSkipVenueEventDetails"> <strong>Skip Venue & Event Details</strong>
You could simply add an event listener to the "change" event of the select and based on the value that is selected you can change the attribute "checked" of the checkbox
html:
<html>
<head></head>
<body>
<select id="select">
<option value="a" selected>something</option>
<option value="b">check</option>
</select>
<label>
<input id="checkbox" type="checkbox">
Checkbox
</label>
<script>
let select = document.getElementById("select");
let checkbox = document.getElementById("checkbox");
select.addEventListener("change", function () {
checkbox.checked = select.value !== "a";
});
</script>
</body>
</html>