This is a migrated thread and some comments may be shown as answers.

Set text with custom parameters in JavaScript

0 Answers 124 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Dennis
Top achievements
Rank 1
Dennis asked on 17 May 2017, 02:14 PM

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>

No answers yet. Maybe you can help?

Tags
ComboBox
Asked by
Dennis
Top achievements
Rank 1
Share this question
or