Avatar of AkAlan
AkAlan
 asked on

How to use jQuery to reset RadComboBox

I have an existing javascript function that I am using to clear the contents of various controls on a page and I want to start using jQuery to do the same thing. I have added a Telerik RadComboBox to my page and I want to reset its value to "2". Can someone help me with the syntax so I can get an idea of how to change the rest of the controls as well.
This is the RadComboBox: 

<telerik:RadComboBox ID="rcbStatus"  runat="server">
       <Items>
        <telerik:RadComboBoxItem Selected ="true"  Value="2" Text="On Order" ToolTip="Not received at Site" />
        <telerik:RadComboBoxItem Value="0" Text="Received" />
        <telerik:RadComboBoxItem  Value="1" Text="Cancelled" />
        <telerik:RadComboBoxItem  Value="3" Text="Show All" ToolTip="Show all orders regardless of their status" />
       </Items>
       </telerik:RadComboBox>

Open in new window

function clearControls() {

document.getElementById('<%=txtJcn.ClientID%>').value = '';
document.getElementById('<%=txtJobID.ClientID%>').value = '';
document.getElementById('<%=txtPo.ClientID%>').value = '';
document.getElementById('<%=txtDateSerial.ClientID%>').value = '';
document.getElementById('<%=txtShop.ClientID%>').value = '';
document.getElementById('<%=txtNomenclature.ClientID%>').value = '';
document.getElementById('<%=ddlRequestor.ClientID%>').selectedIndex = "-1";
document.getElementById('<%=ddlSites.ClientID%>').selectedIndex = "-1";
   }

//Here is where I want to set the control rcbStatus to the //selected value of "2"
</script>

Open in new window

JScriptASP.NET

Avatar of undefined
Last Comment
AkAlan

8/22/2022 - Mon
HainKurt

maybe it does not support any client side functionality.. it looks like it is a server side component only...
even if you can do it on client side, it wont be reflected on the server side...

you can try this

var combo = $find('<%=RadComboBox1.ClientID%>');
combo.SetValue("2");
disrupt

HainKurt

disrupt, according to that article (they keep changing all API with every version :) this may work

<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript" ></script>

$telerik.$("#<%= RadComboBox1.ClientID %>").val("2");
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
disrupt

Yeah it seems to be that way!
leakim971

Look like the job is not totally done...
http://www.telerik.com/help/aspnet/combobox/combo_client_model.html

The following work a way...
$telerik.findComboBox("RadComboBoxDealer").set_value(2);
$telerik.findComboBox("RadComboBoxDealer").set_text("On Order");

Open in new window


Most of the method only work on the server side (code behind)


function clearControls() {

document.getElementById('<%=txtJcn.ClientID%>').value = '';
document.getElementById('<%=txtJobID.ClientID%>').value = '';
document.getElementById('<%=txtPo.ClientID%>').value = '';
document.getElementById('<%=txtDateSerial.ClientID%>').value = '';
document.getElementById('<%=txtShop.ClientID%>').value = '';
document.getElementById('<%=txtNomenclature.ClientID%>').value = '';
document.getElementById('<%=ddlRequestor.ClientID%>').selectedIndex = "-1";
document.getElementById('<%=ddlSites.ClientID%>').selectedIndex = "-1";
$telerik.findComboBox("RadComboBoxDealer").set_value(2);
$telerik.findComboBox("RadComboBoxDealer").set_text("On Order");
   }
</script>

Open in new window

leakim971

replace RadComboBoxDealer by : <%= rcbStatus.ClientID %>  of course

rcbStatus

Else to clear (empty) the combobox you may use :
$telerik.findComboBox("<%= rcbStatus.ClientID %>").clearSelection();

Open in new window

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
AkAlan

ASKER
leakim, You answer so far is the only one I could get to do anything. It does clear the selection, the problem is I want it set to a Selected Value of 2. Where can I see all the options taht are available to me so I can learn it?
ASKER CERTIFIED SOLUTION
leakim971

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
AkAlan

ASKER
That did the trick, Thanks. So I guess Ineed to put "$Telerik." in front of any command that is going to reference a Telerik control and the rest is standard jQuery.
leakim971

yes, when you play with multiple plugin that's a good practice
for example use jQuery instead $

<< Look like the job is not totally done... >>
I saw a lot of Telerik's functions not working, so be aware of the futures updates, Telerik will certainly propose a better way to set the default combo item (with javascript) one day...
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
AkAlan

ASKER
I am pretty new to jQuery so I'm not really sure but I think the only plugin I have is from Telerik. I say that because I added this code to my Master page:
 <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        <Scripts>
            <%--Needed for JavaScript IntelliSense in VS2010--%>
            <%--For VS2008 replace RadScriptManager with ScriptManager--%>
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
        </Scripts>
    </telerik:RadScriptManager>
this is the only reference to jQuery in my project.