I am creating a form with 2 dropdowns 1 for service and 1 for staff. The staff members are linked to a service, therefore when a service is selected in the first select, only those linked to that service will be available in the 2nd select. My current form code is:
<select name="service" id="service">
    <option data-id="1">Service 1</option>
    <option data-id="2">Service 2</option>
    <option data-id="3">Service 3</option>
</select>
<select name="staff" id="staff">
    <option data-id="1">Staff 1</option>
    <option data-id="1 2">Staff 2</option>
    <option data-id="1 3">Staff 3</option>
</select>
You will see that a staff member may offer more than 1 service (I have removed the values for simplicity).
The only jQuery I have right now is reading the value of the selected attribute in #service:
<script>
    $("#service").on("change", function() {
        id = ($(this).find(":selected").data("id"));
    });
</script>
This returns the correct value if I do alert(id).
This is the first time I have ventured into data attributes, but in my head it would do an each() on staff > option, and if they dont contain the selected service id in the data-id, then disabled should be added to the option.
Thank you all
 
     
    