Link to home
Start Free TrialLog in
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

Avatar of HainKurt
HainKurt
Flag of Canada image

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, 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");
Yeah it seems to be that way!
Avatar of 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

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

Avatar of AkAlan
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
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 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.
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...
Avatar of 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.