How to add labels to dropdown menu if the select options are coming from datatables javascript?

How to add labels to dropdown menu if the select options are coming from datatables javascript?

Noodles12Noodles12 Posts: 113Questions: 41Answers: 2

I am using a datatable with dropdown filter for my project where I am popoluating the dropdown menu dynamically from the datatable. Automated 508 complaince tool is throwing the following error for the 3 dropdowns- "Elements with No Accessible Name: (3)". It also provides link to the following site on how to fix the error. https://www.ssa.gov/accessibility/andi/help/alerts.html?no_name_form_element.

I am not sure how to add labels since I am not defining the select options in the HTML. It is coming from Javascipt. Please see the code below. Any guidance will be very helpful. Thanks.

https://live.datatables.net/finezici/1/edit

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,342Questions: 26Answers: 4,954

    Just add the label attribute to the option string built in this loop.

        column.data().unique().sort().each(function(d, j) {
    select.append('<option value="' + d + '">' + d + '</option>');
    
        });
    

    Kevin

  • Noodles12Noodles12 Posts: 113Questions: 41Answers: 2

    Thankyou, I am not a javascript expert. Is this how I add it?

    column.data().unique().sort().each(function(d, j) {
    select.append('<option value="' + d + '">' + d + '</option>');
    select.append('<option label="text">' + d + '</option>');

    });
    
  • Noodles12Noodles12 Posts: 113Questions: 41Answers: 2
    Answer ✓

    Please ignore. I figured it out. Thanks for your time.

Sign In or Register to comment.