Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9271995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:45:38+00:00 2026-06-18T15:45:38+00:00

Good Day I have a dynamically populated drop down list with list options .

  • 0

Good Day

I have a dynamically populated drop down list with list options .
Problem is that when I choose and option from the list, it applies a spacing ( ) to the left of the text as it would appear in the tree stucture

Now the list is styled in a tree stucture and is called from another loation on the server. I cannot change the spacing in that. (since t forms the tree structure effect)

Look at my code below:

HTML

<select id="AreaTreeSelect" data-bind="value: RiskAssessment.AreaId"></select>

Jquery

               $.ajax({
                    url: "API/DataHandler.ashx?method=getareatree",
                    contentType: "application/json; charset=utf-8",
                    success: function (result) {
                        for (var i in result) {
                            var obj = result[i];

                            $("#AreaTreeSelect").append("<option value=\"" + obj.Id + "\">" + obj.Name + "</option>");

                        }
                    }
                });

This is how it populates in the browser:

<select id="AreaTreeSelect" data-bind="value: RiskAssessment.AreaId">
<option value="156">Ferrometals</option>
<option value="158">&nbsp;&nbsp;Admin &amp; Finance</option>
<option value="169">&nbsp;&nbsp;&nbsp;&nbsp;Warehousing</option>
<option value="170">&nbsp;&nbsp;&nbsp;&nbsp;Procurement</option>
<option value="171">&nbsp;&nbsp;&nbsp;&nbsp;Acounting</option>
<option value="855">&nbsp;&nbsp;&nbsp;&nbsp;Information Technology</option>
<option value="159">&nbsp;&nbsp;HR</option>
</select>

etc…

How do I remove the space when the option is selected an displayed in the select box?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T15:45:39+00:00Added an answer on June 18, 2026 at 3:45 pm

    Maybe this could be worth trying:

    $('#AreaTreeSelect').change(function(){
        $(this).find('option.trimmed').each(function(){
            var padding = '';
            for(var i=0; i<$(this).data('numSpaces'); i++){
                padding += String.fromCharCode(160);
            }
            $(this).text(padding + $(this).text());
        })
        .removeClass('trimmed');
        var selOpt = $(this).find('option:selected');
        var numSpaces = selOpt.text().replace(/^(\s*).*/, '$1').length;
        selOpt
            .data('numSpaces', numSpaces)
            .text(selOpt.text().replace(/^\s*/g, ''))
            .addClass('trimmed');
    });
    

    The idea is that it removes all &nbsp; from the currently selected option, but remembers how much padding there was and restores the padding when another option is selected.

    Obviously, you could store the actual sequence of &nbsp; instead of the number of them, and get rid of a few lines of code.

    See working fiddle here: http://jsfiddle.net/aKGac/1/

    The obvious downside with this solution is that the currently selected option will appear in the list without any indentation when it is expanded:

    No indentation on selected option

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good day code knights, I have a tricky problem that I cannot see a
Good day I have a custom TextBox that has a IndicatorTextBox.ui.xml file as well
Good day, I have a class that implements the LoaderCallbacks, and hence have the
Good Day, I have a simple working routine in Perl that swaps two words:
Good Day, I have a Hibernate mapping that looks something like this: public class
Good day, I have created an object that will manage data access. My app
Good day! I have a quite strange problem. I have installed joomla on one
Good day! I have an event handler that, when you add a document to
Good day, I have a local csv file with values that change daily called
Good day I have gridview that contains a link button. How can I retrieve

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.