Retrieving RadCombobox "Type" Via JavaScript

5 posts, 0 answers
  1. Brad
    Brad avatar
    22 posts
    Member since:
    Nov 2011

    Posted 15 Oct 2012 Link to this post

    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.
  2. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 17 Oct 2012 Link to this post

    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.
  3. Brad
    Brad avatar
    22 posts
    Member since:
    Nov 2011

    Posted 25 Oct 2012 Link to this post

    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 :)
  4. Brad
    Brad avatar
    22 posts
    Member since:
    Nov 2011

    Posted 26 Oct 2012 Link to this post

    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.
  5. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 30 Oct 2012 Link to this post

    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.
Back to Top