Javascript "Type" Issue

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

    Posted 18 Jan 2012 Link to this post

    Hello

    I'm writing some javascript that will allow our users to navigate through the fields of a webpage using their keyboard and either the enter or down arrows in addition to the default tab keystroke. This is working great however there are some quirks when it comes to the combobox, as hitting down it should select the next item and not jump out.  Instead it is doing both and even after switching fields it leaves the combobox open.  Much like I did for the radiogroup I wanted to make it so down would cycle through each option until the last when it would break out of the combobox and onto the next control.  I have been unable to do this as the javascript type is always returned as text, I assume this is because behind the scenes the rad combobox is actually a set of stacked text fields. That's all fine and dandy however I need a way to distinguish this control from other control types.

    Here's some sample code:

        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);
                }
          }
       }

    I stripped out most of the logic here, all it's doing is listening for a keypress and if it's enter or down it will show the control type.  As already said I'm getting "text" for a combobox which leave same with no way to identify it (without knowing the name ahead of time,which isn't an option here). 

    So my questions is: is there a way to get the type of the combobox control through JavaScript? Or is this a bug in the telerik controls that needs to be fixed?

    Thanks in advance :)
  2. Kevin
    Kevin avatar
    360 posts
    Member since:
    Jul 2012

    Posted 19 Jan 2012 Link to this post

    Hello Brad,

    For the RadComboBox items, instead of using type to determine if it's a RadCombBox item. The RadComboBox has an "_itemTypeName" attribute on the element that you can use to determine if it's a RadComboBoxItem.

    I hope that helps.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Brad
    Brad avatar
    22 posts
    Member since:
    Nov 2011

    Posted 20 Jan 2012 Link to this post

    Thanks for the response, I've tried to use this and have found it just comes back as undefined.

    <script language="javascript" type="text/javascript">
        // Monitor keystrokes for {enter} or {down arrow}
        document.onkeydown = function (e) {
            //document.onkeypress = 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(
                        "ID : " + currentField.id + "\r\n" +
                        "Name : " + currentField.name + "\r\n" +
                        "Type : " + currentField.type + "\r\n" 
                        "ItemTypeName : " + currentField._itemTypeName + "\r\n" 
                    );
    ...

    Is there something I'm missing?  I tried researching that command but wasn't really getting any results.
  5. Ivana
    Admin
    Ivana avatar
    657 posts

    Posted 21 Jan 2012 Link to this post

    Hello Brad,

    e.target.type returns the type of the control /element that initiated the key press event. When Enter is pressed onto a radio button it returns type "radio", or "text" when key is pressed onto a input that has type "text".

    Could you explain a little bit more what exactly are you trying to achieve?

    Kind regards,
    Ivana
    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
  6. Brad
    Brad avatar
    22 posts
    Member since:
    Nov 2011

    Posted 23 Jan 2012 Link to this post

    Ivana, as said in my original post:

    "I'm writing some javascript that will allow our users to navigate through the fields of a webpage using their keyboard and either the enter or down arrows in addition to the default tab keystroke."

    Not sure how much more I could elaborate on that. If there's something specific you need me to explain, then by all means let me know.
  7. Ivana
    Admin
    Ivana avatar
    657 posts

    Posted 25 Jan 2012 Link to this post

    Hello Brad,

    Could you isolate this issue in a sample page and send it to us via a support ticket? This way we will be able to troubleshoot the exact same scenario you have troubles with.

    Kind regards,
    Ivana
    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
UI for ASP.NET Ajax is Ready for VS 2017