Click here to Skip to main content
15,905,232 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I want to set this function on button keypress !
How does i do this ?
JavaScript
this.keydown(function (ev) {

                    if (ev.which === 13 && !ev.shiftKey){
                        ev.preventDefault();

                        var body = $(this).val();

                        if ( $.trim(body) == '')
                            return;

                        options.sendMessage(body);

                        if (options.dialogWindowHeight > 0){
                            options.messageListControl.height( options.dialogWindowHeight );
                        }

                        $(this).attr('rows', 1);
                        $(this).css('height', options.textareaHeight);

                        options.scrollDialog();
                    }
                    else if (ev.which === 13 && ev.shiftKey){
                        self.adjust();
                    }
                    else if (ev.which === 8){
                        self.adjust();
                    }
                    else{
                        self.adjust();
                    }
                });
Posted

1 solution

Wrap it around in a function and call the function from within click event. This uses jQuery, but it is simple to change to "plain" javascript.

Short example:
JavaScript
function setKeyDown(selector) {
$(selector).on("keydown", "", function (e){
// your code
});
}

function buttonClick() {
// you button code
setKeyDown("txtPrice");
setKeyDown("txtQuntity");
}


If this helps please take time to accept the solution.
 
Share this answer
 
Comments
Member 12657916 6-Sep-17 8:57am    
how to set a keypress function on button onclick ?
Member 12657916 6-Sep-17 8:58am    
<?php echo esc_attr($seacrchBtnText); ?>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900