1

i wants to submit a php form with any of function key or a Any of keyboard shortcut key.

I try following code. In that i do operation using keyboard keycode. but its not submits the form. Press "TAB" button from Keyboard

document.onkeydown=function(evt){
        var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) : event.keyCode;
        if(keyCode == 9)
        {
            //your function call here
            document.test.submit();
            alert("Key Pressed");
        }
    }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<?php 
if(isset($_POST['search']))
{
    echo $search = $_POST['search'];
}
?>
<body>
<form name="test" action="#" method="POST">
 <input type="text" name="search" />
</form>
</body>

I wants to submit a PHP form with any of Function key or Any of combinations or shortcut key. So How can I do it with JQUERY,JS,AJAX OR PHP.

  • `any of Function key or Any of combinations or shortcut key`:- what happen if user want to type `a@gmail.com` (conside `@`there). Just after hiting `@` from will submit and `gmail.com` will never be added. it's not a good practice to do in this way. But wait. You will get answer for-sure – Alive to die - Anant Sep 02 '17 at 05:26
  • for that i need to use only key combinations.so is there any way to submit a form using any of key combinations. Like Ctrl + A –  Sep 02 '17 at 05:31
  • https://stackoverflow.com/questions/10655202/detect-multiple-keys-on-single-keypress-event-in-jquery/10655316#10655316 – Alive to die - Anant Sep 02 '17 at 05:33
  • You form to do get submitted on tab click . What else you want ? – Amar Singh Sep 02 '17 at 05:52
  • Its not working bro. See [link](https://jsfiddle.net/webster18/psdjcdv4/) –  Sep 02 '17 at 05:55
  • I want to submit a Form With Any Of Keyboard Key Combination –  Sep 02 '17 at 05:56
  • any of the keyboard key or only function keys ? – Amar Singh Sep 02 '17 at 06:13
  • Any Of Keyboard Key Combination Or Function Key. any of both. –  Sep 02 '17 at 06:18

3 Answers3

1

I founded a JS to Allow Form Submit using keyboard key combination. It quite easy. See Code

    shortcut.add("Ctrl+B",function() {
    document.getElementById("sbmt").click();
    alert("Form Submitted...");
    },{
      'type':'keydown',
      'propagate':true,
      'target':document
    });

When Press Ctrl + B Form Was Submits. This is Link to JS openjs To Allow Shortucut

Amar Singh
  • 5,464
  • 2
  • 26
  • 55
0

try this it will work.

document.onkeydown=function(evt){
    var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) : event.keyCode;
    if(keyCode == 9)
    {
        //your function call here
        document.forms["test"].submit();
        alert("Key Pressed");
    }
}

Check this code in your local not on third party. This will work perfect on localhost. this is work for me.

Devendra Gokhe
  • 187
  • 1
  • 1
  • 10
0

Checkout this if you want to submit on click of any function keys JsFiddle

$(document).keyup(function(e) {
   if(e.which <124 && e.which >111){
   alert('function keys');
   //submit your form here
   }

});
Amar Singh
  • 5,464
  • 2
  • 26
  • 55