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

Retrieving RadCombobox "Type" Via JavaScript

4 Answers 140 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Brad
Top achievements
Rank 1
Brad asked on 15 Oct 2012, 06:23 PM
I'm having an issue retrieving the type of a control if it is a Combobox.  All other control types work fine but the combobox always gets reported back to me as type "text".  Here is some trimmed down, generic code that will illustrate what I am trying to do.  This javascript is placed in a shared JS file that is executed on every page and will be invoked any time a person presses down or enter on their keyboard.
 
document.onkeydown = function (e) {
     e = e || window.event;
     if (typeof e != 'undefined') {
         var tgt = e.target || e.srcElement;
 
        // If the keypress was ENTER (13) or DOWN (40)
         if (e.keyCode == 13 || e.keyCode == 40) {
             // Determine which element we're currently on
             currentField = e.target;
              alert(currentField.type);
         }
   }
}

Thanks in advance.

4 Answers, 1 is accepted

Sort by
0
Kalina
Telerik team
answered on 17 Oct 2012, 03:41 PM
Hi Brad,

You can get all the RadComboBox instances on your page at client-side easily as an array:

function pageLoad() {
    var combos = Telerik.Web.UI.RadComboBox.ComboBoxes;
  
        if (combos != null) {
            for (var i = 0; i < combos.length; i++) {
                var combo = combos[i];
                alert(combo.get_text());
 
            }
        }
}


All the best,
Kalina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Brad
Top achievements
Rank 1
answered on 25 Oct 2012, 07:41 PM
Thanks, that's not exactly what I was looking for as I need a specifc combobox, but I was able to make it work by iterating through each option and matching their IDs.  Is there not a way to directly access a specfic one?

Also, using what you provided I was able get a lot closer to what I was trying to accomplish and I now have the down arrow iterating through each control on the scren and when it hits a combobox it will instead jump through each option and then when it gets to the last one it will jump out and onto the next control.  The problem is it is leaving the combobox highlighted in orange despite having tried several things.  I have tried the following:

combo.toggleDropDown();
combo.hideDropDown();
combo.get_HighlightedItem().unHighlight();

The hideDropDown option works for the most part, but it doesn't unselect the item afterwards.

Here's an image that shows that's happening fter they are closed: http://i.imgur.com/QA8I3.png

As you can see several comboboxes look like they are the active control.

Any tips?  Thanks :)
0
Brad
Top achievements
Rank 1
answered on 26 Oct 2012, 08:22 PM
Also, is there a way to select other controls in the same manner that you did with the combobox?  For example I tried a radnuemric textbox and had no luck.  This is what I used:

var c = Telerik.Web.UI.RadNumericTextBox.RadNumericTextBoxes;

But c comes back as undefined.  Whereas if I take off the last part I can get just one instance of a RadNumericTextBox but it doesn't give me a specific one.
0
Kalina
Telerik team
answered on 30 Oct 2012, 02:57 PM
Hello Brad,

I am afraid that obtaining all control instances at client-side as an array is not supported by RadNumericTextBox.
You can get the RadNumericTextBox client-side instance by ClientID - as is described in this help article.

Regards,
Kalina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
ComboBox
Asked by
Brad
Top achievements
Rank 1
Answers by
Kalina
Telerik team
Brad
Top achievements
Rank 1
Share this question
or