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

Javascript "Type" Issue

5 Answers 90 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Brad
Top achievements
Rank 1
Brad asked on 18 Jan 2012, 09:51 PM
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 :)

5 Answers, 1 is accepted

Sort by
0
Kevin
Top achievements
Rank 2
answered on 19 Jan 2012, 02:39 PM
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.
0
Brad
Top achievements
Rank 1
answered on 20 Jan 2012, 08:52 PM
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.
0
Ivana
Telerik team
answered on 21 Jan 2012, 05:31 PM
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
0
Brad
Top achievements
Rank 1
answered on 23 Jan 2012, 03:00 PM
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.
0
Ivana
Telerik team
answered on 25 Jan 2012, 05:46 PM
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
Tags
ComboBox
Asked by
Brad
Top achievements
Rank 1
Answers by
Kevin
Top achievements
Rank 2
Brad
Top achievements
Rank 1
Ivana
Telerik team
Share this question
or