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

Define onClientKeyPressed via JavaScript in pageLoad

2 Answers 81 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 08 Jun 2015, 09:07 PM

How can I add an event handler via JavaScript in pageLoad to handle the keyPress event of a RadComboBox? 

We create a series of ComboBox controls dynamically based on user preferences.  We want to be able to accept user keystrokes and when they press the Enter key, fire the rrKeyPress event.

We're unable to define this in our code due to business constraints; it *MUST* be in JavaScript on pageLoad.

I've tried adding it using the code below, but it didn't work as expected:

// Loop through controls and attach

var comboBox = document.getElementById('RadComboBox1');
comboBox.add_valueChanged(rrKeyPress);

Any suggestions?

2 Answers, 1 is accepted

Sort by
0
Accepted
Plamen
Telerik team
answered on 10 Jun 2015, 06:26 AM
Hello,

Here is the code that worked correctly at my side:
<script type="text/javascript">
 
          function pageLoad() {
              var combo = $find("<%=RadComboBox1.ClientID%>");
              combo.add_keyPressing(
                  function(sender, args) {
                      alert(args.get_domEvent().keyCode);
                  });
          }
      </script>
      <div>
          <telerik:RadComboBox runat="server" ID="RadComboBox1">
              <Items>
                  <telerik:RadComboBoxItem Text="aaa" />
                  <telerik:RadComboBoxItem Text="bbb" />
                  <telerik:RadComboBoxItem Text="ccc" />
 
              </Items>
 
          </telerik:RadComboBox>
      </div>

Hope this will help you solve the issue.

Regards,
Plamen
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Matt
Top achievements
Rank 1
answered on 11 Jun 2015, 02:20 PM
Thanks...worked like a champ!
Tags
ComboBox
Asked by
Matt
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Matt
Top achievements
Rank 1
Share this question
or