popmotsy Posted July 22, 2009 Share Posted July 22, 2009 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 Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 22, 2009 Share Posted July 22, 2009 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> Quote Link to comment Share on other sites More sharing options...
popmotsy Posted July 23, 2009 Author Share Posted July 23, 2009 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. Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 23, 2009 Share Posted July 23, 2009 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. Quote Link to comment Share on other sites More sharing options...
popmotsy Posted July 24, 2009 Author Share Posted July 24, 2009 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.. Quote Link to comment Share on other sites More sharing options...
popmotsy Posted July 24, 2009 Author Share Posted July 24, 2009 hi,, If Any one else know about the solution or any tricks,,,,, please please,,giv me reply. Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 24, 2009 Share Posted July 24, 2009 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. Quote Link to comment Share on other sites More sharing options...
popmotsy Posted July 24, 2009 Author Share Posted July 24, 2009 ok fine... you are right , i just want to copy or delete data up to the selected textboxes.. first select using shift+arrow key and just paste the data. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.