Populate dropdown select with array using jQuery

后端 未结 8 1907
花落未央
花落未央 2020-11-29 08:07

I am trying to populate a dropdown select with an array using jQuery.

Here is my code:

        // Add the list of numbers to the drop down here
              


        
8条回答
  •  甜味超标
    2020-11-29 08:38

    The solution I used was to create a javascript function that uses jquery:

    This will populate a dropdown object on the HTML page. Please let me know where this can be optimized - but works fine as is.

    function util_PopulateDropDownListAndSelect(sourceListObject, sourceListTextFieldName, targetDropDownName, valueToSelect)
    {
        var options = '';
    
        // Create the list of HTML Options
        for (i = 0; i < sourceListObject.List.length; i++)
        {
            options += "\r\n";
        }
    
        // Assign the options to the HTML Select container
        $('select#' + targetDropDownName)[0].innerHTML = options;
    
        // Set the option to be Selected
        $('#' + targetDropDownName).val(valueToSelect);
    
        // Refresh the HTML Select so it displays the Selected option
        $('#' + targetDropDownName).selectmenu('refresh')
    }
    
    
    

提交回复
热议问题