Hi,
Is there any way to set the SelectedIndex of a RadComboBox via javascript?
I've managed to set the text to blank via this code:
var combo = $$('.wherecombotown')[0];
combo.getElementsBySelector('input')[0].value = '';
However this still keeps the selected index the same; I can't seem to find any way of setting the index back to -1;
Many thanks,
Ben
Is there any way to set the SelectedIndex of a RadComboBox via javascript?
I've managed to set the text to blank via this code:
var combo = $$('.wherecombotown')[0];
combo.getElementsBySelector('input')[0].value = '';
However this still keeps the selected index the same; I can't seem to find any way of setting the index back to -1;
Many thanks,
Ben
4 Answers, 1 is accepted
0

Alexandre
Top achievements
Rank 1
answered on 16 Nov 2008, 03:04 PM
Hi Jon,
Take a look in your local documentation
ms-help://telerik.aspnetajax.radcontrols.2008.Q3/telerik.aspnetajax.radcombobox.2008.Q3/client-side-radcombobox.html
Select a specific element
var combo = $find("<%= RadComboBox1.ClientID %>");
var itm = combo.findItemByValue(myItemValue);
itm.select();
Clear selection
var combo = $find("<%= RadComboBox1.ClientID %>");
combo.clearSelection();
Hope this help :)
Take a look in your local documentation
ms-help://telerik.aspnetajax.radcontrols.2008.Q3/telerik.aspnetajax.radcombobox.2008.Q3/client-side-radcombobox.html
Select a specific element
var combo = $find("<%= RadComboBox1.ClientID %>");
var itm = combo.findItemByValue(myItemValue);
itm.select();
Clear selection
var combo = $find("<%= RadComboBox1.ClientID %>");
combo.clearSelection();
Hope this help :)
Quba
commented on 17 Nov 2008, 08:40 AM
Top achievements
Rank 2
Thanks for the reply Alexandre.
Unfortunately I can't get this method to work, it just throws a JavaScript error saying the method is not supported. I'm using the prototype library so am wondering if this is overriding the "Find" and "ClientID" methods/properties. Is there any other way of changing the selected index?
Many thanks
Unfortunately I can't get this method to work, it just throws a JavaScript error saying the method is not supported. I'm using the prototype library so am wondering if this is overriding the "Find" and "ClientID" methods/properties. Is there any other way of changing the selected index?
Many thanks
0
Hello Jon,
I suggest you use Telerik.Web.UI.RadComboBox.ComboBoxes array to obtain the client-side instance of the combobox instead of "Find" method. Please let us know how it goes.
Kind regards,
Yana
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
I suggest you use Telerik.Web.UI.RadComboBox.ComboBoxes array to obtain the client-side instance of the combobox instead of "Find" method. Please let us know how it goes.
Kind regards,
Yana
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0

Chandrashekhar
Top achievements
Rank 1
answered on 04 Apr 2009, 07:07 AM
Hello Charlie,
Try following solution -
To set combo box index :
var itemLocation = comboLocations.findItemByText("Select Location");
itemLocation.select();
Regards,
Chandrashekhar Mahale
Try following solution -
To set combo box index :
var itemLocation = comboLocations.findItemByText("Select Location");
itemLocation.select();
Regards,
Chandrashekhar Mahale
0

Fernando
Top achievements
Rank 2
answered on 04 Sep 2015, 12:43 PM
I'm sorry for writing in a post as old, but to help others who come here in the future, I felt obliged to inform a way that I find simpler for set SelectedIndex via JavaScript. Today we can do like this:
var
combo = $find(
"RadComboBox1"
);
combo.trackChanges();
combo.get_items().getItem(0).select();
combo.commitChanges();
Hi,
I have the same problem as Charlie got. when I try using the clearSelection(), it just throws a JavaScript error saying the method is not supported. Any clues?
Wei
It is working as expected when tried clearSelection() method in my end. I guess you are using different version of RadControls. Could you let us know which version of RadControls that you are using? Here is the code that I tried for RadControls for ASP.NET AJAX version (Q1 2009).
ASPX:
JavaScript:
Thanks,
Shinu
Hi Shinu,
Thanks for the quick response. I tried again and you are right the clearSelection works.
Now the new issue is, I use the RadCombobox(ddlSearchCity) to build a usercontrol utrlCity and use utrlCity to build another usercontrol utrlAddress. I put utrlAddress in one page and it works, but when I go to another page, which contains utrlCity, it throws an error: ‘null is null or not an object, with the line “ddlSearchCity.clearSelection” highlighted.
sbClientScript.Append("var ddlSearchCity = $find('" + ddlSearchCity.ClientID + "');" + Environment.NewLine)
'sbClientScript.Append("var ddlSearchCity = $find('<%= " + ddlSearchCity.ClientID + " %>');" + Environment.NewLine) 'This doesn’t work --'Null' is null or not an object
sbClientScript.Append("ddlSearchCity.clearSelection();" + Environment.NewLine)
sbClientScript.Append("ddlSearchCity.set_emptyMessage('" + strEnter + "');" + Environment.NewLine)
Do you happen to have an example illustrates the RadCombobox used in a usercontrol?
I have a similar problem when selecting an item via JavaScript. Why I can't use an item.select()? I have got an error :
"Microsoft JScript runtime error: Out of memory"...
item.select();
If I set a break point on JS code, I can see valid item object with their methods, etc. I can't use
var combo = $find("<%= RadComboBox1.ClientID %>");
because the RadCombobox is in an EditItemTemplate.
Thank you,
at
All the best,
Simon
the Telerik team
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
I can select the item through item.select(); but the problem am facing is that, my combobox has AutoPostback set to true. So when I do item.select() in javascript, post back is happening, which is not needed. Please help me how to do item.select() without postback.
You can avoid the postback in this case with the following code:
var
$RCBP = Telerik.Web.UI.RadComboBox.prototype;
var
postback = $RCBP.postback;
$RCBP.postback =
function
() { };
item.select();
$RCBP.postback = postback;
I hope this helps.
All the best,
Simon
the Telerik team
Even though the post back can be avoided, the item.Select() fired the CausesValidation event. Some code similar to the one you have mentioned could avoid that.
I could make that working by a different method.
radCombo.set_text("aTextFromTheDropDown");
This happened to be purely client side.(no post back, no validation issues)
'aTextFromTheDropDown' can be retrieved based on the value using the function get_itemByValue("0").get_text();
P.S: The Method names are case sensitive and list of methods available can be found using the debugger.
This does not work for an auto complete combo box which get its items from a web service.
I'm working with version 2011.1.413.40
I tried several options with no luck...
It's expected that when you set some text in the input of the RadComboBox and load on demand is used, a request for items is performed. Could you elaborate a bit more on the exact scenario that you want to achieve?
Best wishes,
Dimitar Terziev
the Telerik team
var
$RCBP = Telerik.Web.UI.RadComboBox.prototype;
var
postback = $RCBP.postback;
$RCBP.postback =
function
() { };
item.select();
$RCBP.postback = postback;
Post back works perfectly most of the time, after a few page reload, it stops working.
We have a controls 2 places, One on the main page and one on the popup. (both are expected to be in sync)
Step1:
Say user on the main page selection,
Option-A : Page post back's Ok.
Now user opens the pop up and selects, Option-B, on closing the pop up. We select Option-B in the main window.
User repeats step1, So main page has option-B selected again.
Again user selects Option-A and it does not post back.
looks like post back is not working on previously selected item.
Not sure how to debug and resolve this. Any suggests would help.
Hi Vijay,
The issue you're encountering with the combobox not triggering a postback under certain conditions seems to be related to the state management of the control. Unfortunately, without more information about your code and the specific issue you are facing, it is difficult to provide a definitive solution. However, here are some suggestions that might help:
If you are unable to find the reason for the issue and fix, isolate it in a simple runnable project and send it for examination via a new support ticket.