Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to set an HTML button as default inside a form?

I'm working on a asp.net page and I have several buttons in my page, some of them are asp.net buttons, other are HTML input[type=button] elements. HTML buttons are used to make AJAX calls.

When the user press ENTER I need to set as default button one of these HTML buttons, but at the moment the first button in the page is trigged.

Is there a way to set a plain HTML button as default on my form?

like image 582
davioooh Avatar asked Dec 21 '22 12:12

davioooh


1 Answers

Try this :

   // JavaScript Code
   var body = document.getElementsByTagName('body')[0];
    body.onkeydown = function (e) {
        if (e.keyCode === 13) {  //enter key code
         // call your html button onclick code here
        }
    }
like image 129
Mohit Pandey Avatar answered Jan 17 '23 18:01

Mohit Pandey