user828122
user828122

Reputation: 7

save form using the keyboard shortcut

i have form with some fields and a save button. On clicking save all the records are inserted into the table. Now i want to add this data throuth keyboard shortcut. i.e. if i enter (shift+V) capital v then the record has to be inserted. Is it possible? anybody can help me plz?

thanks.

Upvotes: 0

Views: 1075

Answers (2)

c-smile
c-smile

Reputation: 27460

You don't need JavaScript here.

If to assume that your save button is declared as <button type=submit>Save</button> then it is enough to declare accesskey attribute on it like this:

<button type="submit" accesskey="v">Save</button>

This way on Windows you can press Alt + V to activate that button (do its click action). On Mac it will be Cmd + V.

Upvotes: 2

dev4life
dev4life

Reputation: 882

You would have to add the onkeydown and onkeyup method to the document to track when buttons are pressed and when they are released.

var ctrl=false;
var shft=false;

function onkd(e){
  //check event key
  ctrl=true;
  //are all buttons pressed?
      //kick off

}
document.onkeydown = onkd;

function onku(e){
   //check event key
   ctrl=false;

}
document.onkeyup = onku;

Upvotes: 0

Related Questions