Set text with custom parameters in JavaScript

1 posts, 0 answers
  1. Dennis
    Dennis avatar
    7 posts
    Member since:
    Dec 2014

    Posted 17 May 2017 Link to this post

    I have a ComboBox that I would like to change the Text value on the client side using JavaScript.  How can I go about setting the text of a CB by passing a custom parameter.  I would like this to be a universal function so I need to find the object calling the function, set the Substring value based on a passed parameter, and then set the text property of the CB to that.  For example, options are:  

    1 | Item 1

    2 | Item 2

    3 | Item 3

    On the event OnClientSelectedIndexChanged I would like to change the text to only the left character.  What I am looking for is something like this, but works:

    <telerik:RadComboBox ID="rcbItemCode" runat="server" CssClass="block width2" RenderMode="Lightweight" ExpandDirection="Down" DropDownAutoWidth="Enabled" EnableLoadOnDemand="True"
                                                        ShowMoreResultsBox="true" EnableVirtualScrolling="true" OnItemsRequested="rcb_ItemsRequested" OnClientFocus="SetTextOfTheComboBox" OnClientSelectedIndexChanged="function (radcombobox, args) {special(this, args, 1);}" />
     
    <script type="text/javascript">
        function special(sender, eventArgs, len) {
            debugger;
            var item = eventArgs.get_item();
            var clientId = item.get_id();
            var rcb = document.getElementById(clientId);;
            var newText = rcb.get_text().substring(0, len);
            rcb.set_text(newText);
        }
    </script>
Back to Top