Key-event which executes a submit-button

I have a form with different submit-buttons.

What I'm looking for is a way to execute one of this buttons with keyboard-combinations. For instance, I would like the

<input type="submit" name="save" value="save">

button to be executed when I click "Ctrl+C".

Other keycode-combinations should execute other submit-buttons.

The solution only needs to work on IE on PC's.

Thanks in advance

LVL 32
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


I am wondering if you can use the onKeyPress event to capture what keystrokes are pressed, and then use this information to either fire the appropriate button, or at the very least, change the action of the form and the value of the submit button and then submit the form.

Fritz the Blank
here's some simple code

     TD {
var key = new Array();
key['1'] = "page1.html";
key['2'] = "page2.html";
key['3'] = "page3.html";
key['c'] = "page67.html";

function getKey(keyStroke) {
     eventChooser = (isNetscape) ? keyStroke.which : event.keyCode;
     which = String.fromCharCode(eventChooser).toLowerCase();

//     alert(eventChooser);

     for (var i in key)
          if (event.ctrlKey && which == i) {
               window.location = key[i];
          else if(eventChooser == 13) {
               //load page1.html if enter key pressed
               window.location = key[i];

document.onkeydown = getKey;
// -->
        <TD onmouseout="''" onmouseover="'black'">Page<U>1</U></TD>
        <TD onmouseout="''" onmouseover="'black'">Page<U>2</U></TD>
        <TD onmouseout="''" onmouseover="'black'">Page<U>3</U></TD>
        <TD onmouseout="''" onmouseover="'black'">Page<U>C</U></TD>

hope this helps

Here is an article that shows you how to capture the pressed key:
Ensure Business Longevity with As-A-Service

Using the as-a-service approach for your business model allows you to grow your revenue stream with new practice areas, without forcing you to part ways with existing clients just because they don’t fit the mold of your new service offerings.

BatalfAuthor Commented:
I know how to use event.keyCode, event.ctrlKey, but how could I use this to submit the form?

And not by the submit() function because I have several submit-buttons, all identified by different names.
ahosangFinance Systems DeveloperCommented:
Then name the submit button and call click function:;

or whichever submit button you want to fire the action of clicking.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
I was thinking that you could create a JavaScript that would dynamically change the action of the form and the value of the submit button and then execute the submit button; in effect, simulating the click event of your different buttons.

Fritz the Blank
BatalfAuthor Commented:
The action of my form is all to the same page, but based on which submit-button the user pressed, different actions will be executed by serverside-scripts.

I have found a temporary solution, where I use hidden variables<input type="Hidden"> and set a value to them based on which keyboard-shortcut the user pressed. Then I called forms[0].submit(). Then I know I know in my serverside-script what to do based on this hidden-variable.

For instance, if the user presses Ctrl+S, I set the hidden-variable to "S". Then I Submit the page using submit().

Isn't there a simpler way of doing this?

The only thing that I can think of is to set the hidden variable to the value of the submit button in question regardless of whether a shortcut is used or if the button is clicked. That way, you need only interogate the hidden field to pass the parameter back to the page.

Fritz the Blank
ahosangFinance Systems DeveloperCommented:
Didi you try my code?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.