Question:

Functions and javascript?

by  |  earlier

0 LIKES UnLike

Im trying to make a menu on a site that can be used by pushing keyboard buttons. I found a javascript function that i am using, but i have a problem. This is what my js looks like;

document.onkeyup = KeyCheck;

function KeyCheck(e)

{

var KeyID = (window.event) ? event.keyCode : e.keyCode;

switch(KeyID)

{

case 49:

document.Shipping.submit();

break;

case 97:

document.Shipping.submit();

break;

case 50:

document.Recieving.submit();

break;

case 98:

document.Recieving.submit();

break;

case 51:

document.Void.submit();

break;

case 99:

document.Void.submit();

break;

case 52:

document.Ticketing.submit();

break;

case 100:

document.Ticketing.submit();

break;

}

}

Now, I need to make it so when i select a text field, this doesnt apply. If i now type my button into the text field, just as text, it registers it as a button press. I need to do something like onfocus = "somehow make it so that function is negated", to my form

 Tags:

   Report

1 ANSWERS


  1. There are a couple ways to do this.

    You could get rid of document.onkeyup and use access keys instead for your menu navigation.  http://diveintoaccessibility.org/day_15_...

    Or you could use an onfocus event like you said:

    <script>

    navigation = true;

    document.onkeyup = KeyCheck;

    function KeyCheck(e)

    {

    if(!navigation) return;

    var KeyID = (window.event) ? event.keyCode : e.keyCode;

    switch(KeyID)

    {

    case 49:

    document.Shipping.submit();

    break;

    case 97:

    document.Shipping.submit();

    break;

    case 50:

    document.Recieving.submit();

    break;

    case 98:

    document.Recieving.submit();

    break;

    case 51:

    document.Void.submit();

    break;

    case 99:

    document.Void.submit();

    break;

    case 52:

    document.Ticketing.submit();

    break;

    case 100:

    document.Ticketing.submit();

    break;

    }

    }

    </script>

    <input type='text' onFocus = 'navigation=false;' onBlur = 'navigation=true;' />

    There are probably more ways to do this, but I can't think of any.

    Hope this helps.

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.