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

Javascript equivalent of onchange()

1 Answer 996 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Keith
Top achievements
Rank 1
Keith asked on 28 Oct 2016, 07:48 PM

I would like to fire a RadComboBox's SelectedIndexChanged event from another function in JS.  For a standard dropdown list I would use "onchange()" but for the RadComboBox I get TypeError: RadComboBox1.onclick is not a function.  Is there a way to fire a selectedindexchanged event from javascript on a radcombobox?

 

Example:

function fireSelectedIndexChanged() {
    var comboBox = $find("<%=RadComboBox1.ClientID%>");
    comboBox.onchange(); <---- fire selectedindexchanged event
}


1 Answer, 1 is accepted

Sort by
0
Accepted
Anton
Telerik team
answered on 01 Nov 2016, 09:04 AM
Hello Keith,

In order the SelectedIndexChanged event to be fired there has to be a selection on the items in the ComboBox. You can fire it by selecting a different item from the currently selected item and you could do that from any function. Take a look at the code below:

<form id="form1" runat="server">
    <telerik:RadScriptManager runat="server"></telerik:RadScriptManager>
    <div>
        <telerik:RadComboBox ID="RadComboBox1" runat="server" RenderMode="Lightweight"
            OnClientSelectedIndexChanged="OnClientSelectedIndexChanged">
            <Items>
                <telerik:RadComboBoxItem runat="server" Text="Item1" Value="Item1" />
                <telerik:RadComboBoxItem runat="server" Text="Item2" Value="Item2" />
            </Items>
        </telerik:RadComboBox>
    </div>
</form>
<script>
    function pageLoad() {
        var combo = $find("<%= RadComboBox1.ClientID  %>");
        var item = combo.get_items().getItem(0);
        item.select();
    }
 
    function OnClientSelectedIndexChanged(sender, args) {
        alert("SelectedIndexChanged fired from pageLoad");
    }
</script>


Regards,
Anton
Telerik by Progress
Check out the new UI for ASP.NET Core, the most complete UI suite for ASP.NET Core development on the market, with 60+ tried-and-tested widgets, based on Kendo UI.
Tags
ComboBox
Asked by
Keith
Top achievements
Rank 1
Answers by
Anton
Telerik team
Share this question
or