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

Firing the Click Event using jQuery

5 Answers 570 Views
Button
This is a migrated thread and some comments may be shown as answers.
Sébastien
Top achievements
Rank 2
Sébastien asked on 21 Feb 2011, 01:24 PM
Dear Telerik Team,

I am actually migrating the asp:button to telerik:radbutton and some logic doesn't work as expected.
For example, It was easy to use things like that to click a button using jQuery : 

function keyboardActions(event) {
    if (event.keyCode == 13) {
 
        eval($("#<%=btnSearch.ClientID %>").trigger('click')); // Doesn't work with RadButton Q3.2010
        return false;
    }
    //  other keypressed other actions ?
}
 
// If the client press ENTER, the Search button is clicked.
$(document).ready(function () {
    if ($.browser.mozilla) {
        $("#<%=txtName.ClientID %>").keypress(keyboardActions);
        $("#<%=txtCode.ClientID %>").keypress(keyboardActions);
     } else {
        $("#<%=txtName.ClientID %>").keydown(keyboardActions);
        $("#<%=txtCode.ClientID %>").keydown(keyboardActions);
    }
});

How may I do the same logic using RadButton ?

Cheers,

S.F.

5 Answers, 1 is accepted

Sort by
0
Pero
Telerik team
answered on 21 Feb 2011, 03:32 PM
Hello Sébastien,

The RadButton has a click() client-side method, that simulates clicking on the button. You should modify the keyboardActions in the following way:
function keyboardActions(event) {
    if (event.keyCode == 13) {
  
        $find("#<%=btnSearch.ClientID %>").click();
    }
    //  other keypressed other actions ?
}


Best wishes,
Pero
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Sébastien
Top achievements
Rank 2
answered on 22 Feb 2011, 10:07 AM
Thank you for your answer,

Nevertheless, $btnSearch is always null with IE6. It works well with the other web-browsers.
Any idea why ?
Please note that the Script block surrounding this function is embedded in a RadCodeBlock.

function keyboardActions(event) {
    if (event.keyCode == 13) {
  
        var $btnSearch= $find("#<%=btnSearch.ClientID %>");
  
        if ($btnSearch != null) {
            $btnSearch.click();
            return false;
        }
  
    }
}


Cheers,

S.F.
0
Accepted
Cori
Top achievements
Rank 2
answered on 22 Feb 2011, 02:11 PM
Hello Sebastien,

The $find method doesn't require you to include the # sign before the control's id. Remove that and see if it works.
0
Accepted
Pero
Telerik team
answered on 22 Feb 2011, 02:36 PM
Hi Sébastien,

I apologize for giving you incorrect code. The $find shortcut expects the ID of the component to find, and the ID should not start with "#". I simply copied your keyboardActions method and modified only a couple of things, but forgot to remove the "#" character.

Cori, thank you for noticing this!

Best wishes,
Pero
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Sébastien
Top achievements
Rank 2
answered on 22 Feb 2011, 03:40 PM
Thank you both for your answer, it works perfectly now.
It was working with the other browsers because that's their default behavior.

S.F.
Tags
Button
Asked by
Sébastien
Top achievements
Rank 2
Answers by
Pero
Telerik team
Sébastien
Top achievements
Rank 2
Cori
Top achievements
Rank 2
Share this question
or