Jump to content

enable shift+ keys


popmotsy

Recommended Posts

hi to all,,,,

 

 

I want to enable shift+arrow keys in my html table

 

i am using the code below,,but doesnt works

 

here i write code for shift+down arrow key...

 

 

var isshift = false;

$(document).keyup(function (e) {
if(e.which == 16) isshift=false;
}).keydown(function (e) {
if(e.which == 16) isshift=true;
if(e.which == 40 && isshift == true) {

	return false;
}
});

 

 

So please help me if any one know abt that,,,please send me a code for this,,,,thanks

Link to comment
Share on other sites

Here you go. Note that the alerts in the script "traps" the shift down state. So, if you release the shift key while the alert is on screen the code still thinks the shift key is down. I only put those in for demonstration purposes. This shouldn't be an issue if you aren't using an alert on whatever action you are taking in those scenarios. If you are using an alert I would change the shiftKeyDown state to false whenever you trigger one of those states.

 

<html>
<head>
<title>test</title>

<script type="text/javascript">

var shiftKeyDown = false;

function detectShiftArrow(e)
{
    e = e || event;

    if (e.type=='keyup' && e.keyCode==16)
    {
        shiftKeyDown = false;
    }
    else if (e.type=='keydown' && e.keyCode==16)
    {
        shiftKeyDown = true;
    }
    else if (e.type=='keydown' && shiftKeyDown)
    {
        switch (e.keyCode)
        {
            case 37: // Left
                alert('Shift left arrow');
                break;
            case 38: // Up
                alert('Shift Up arrow');
                break;
            case 39: // Right
                alert('Shift Right arrow');
                break;
            case 40: // Down
                alert('Shift Down arrow');
                break;
        }
    }
}

</script>
</head>

<body>
  <input type="text" name="1" onkeydown="detectShiftArrow(event);" onkeyup="detectShiftArrow(event);" />
</body>
</html>

Link to comment
Share on other sites

hi,,,thanks for replying me....

 

Now I got it,,,,

 

but still i hav a problame, i want shift +arrow keys are just work similar

as they are working in EXCEL SHEETS, on my web page.

 

In excel sheet those keys are used for multiple selection of text boxes.

 

Do you hav any idea how to write code for this, thanks.

 

 

Link to comment
Share on other sites

That wasn't what you asked in your original post. Sorry, but it irks me when someone asks for something and then when given what they ask fo, then asks for something different.

 

You need to clarify exactly what you want by the "multiple selection" of cells within an HTML table? What do you want to be able to do once these are selected? I suppose it would be easy enough to "highlight" cells in a table in such a manner, but they wouldn't be "selected". Need more info because I don't think what you want to do can be achieved with Javascript and an HTML table. May have to go with a CSS table and some backdoor trickery. In otherwords it would probably have compatiblity issues.

Link to comment
Share on other sites

hi mjdamato,

 

first sory, i am not asking the whole problame.

 

Actually I have data entry page,on which my client wants to enable

shift+arrow keys for multiple selections, like excel sheets.

 

Hope  this was done through css tables.

 

Well thanks for your help and replying me..

 

 

 

 

Link to comment
Share on other sites

You're still not explaining what the "selection" is for. Let's assume you can select multiple text fields. What then? If you explain what the purpose is, then it helps to provide a solution. The only purpose of selecting multiple fields in an excel table that I can think of would be to delete the data in all the selected cells or copy the data.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.