Wednesday, December 21, 2022
HomeWordPress Developmentcapabilities - Get all customers from function and add to dropdown (choose)...

capabilities – Get all customers from function and add to dropdown (choose) – wordpress, javascript


I’ve a shortcode from capabilities, which retrieves an inventory of all customers from lively function. I’ve managed to get the record into the dropdown record with just a little trickery if I wrap a div across the customers and title it userdiv.

The issue is that regardless of how I attempt to get the customers into the record, they both present up as one selection (all customers) or all of the letters present up as a separate selection.

I’ve this in capabilities:

perform userLooping($function, $img)
{
$user_query = new WP_User_Query( array( 'function' => $function ) );

// Person Loop
if ( !empty( $user_query->outcomes ) ):
        echo '<div id="userdiv">';
    foreach ( $user_query->outcomes as $person ):
        echo '"';
        echo $user->display_name; // show person title
        echo '",';  
    endforeach;
        echo '</div>';
endif;
}
add_shortcode( 'users_role', 'userLooping' );

I’ve put in [users_role] to fetch the customers to the web page (could not want this).
The dropdown has ID input_5_13

Script to get the customers to the dropdown:

       <script>
            
            var choose = doc.getElementById("input_5_13"),
                     arr = [document.getElementById("userdiv").innerHTML];
             
             for(var i = 0; i < arr.size; i++)
             {
                 var possibility = doc.createElement("OPTION"),
                     txt = doc.createTextNode(arr[i]);
                 possibility.appendChild(txt);
                 possibility.setAttribute("worth",arr[i]);
                 choose.insertBefore(possibility,choose.lastChild);
             }
             
        </script>

When the script collects the textual content from userdiv, it finally ends up as an possibility. A protracted line. If I take away [ ] from the script, all letters are fetched in its place.

Tried including " earlier than every person and "," after, however I am unable to get it to work.

If I enter it manually within the script, it really works. Then every person is added as a selection.

var choose = doc.getElementById("input_5_13"),
                      arr = ["user1","user2","user3"];

What am I doing mistaken?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments