473,587 Members | 2,580 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Capturing Key Event

dmjpro
2,476 Top Contributor
Actually what i am trying to do that is to search some data as per users' entries.
Firstly i am fetching the whole data from the database and keeping in a hidden table then as user gives the search string then i manipulate from the hidden table and displaying those into visible one. Now suppose i have huge data and i am performing sequential search so a large no of iterations is going on whenever key pressed. So it slows down the whole process i mean the entered letters are not coming smoothly after the whole search finished then the entered keys displayed in the text box. and if i type so fast then in the mean time browser hanged.

Now i want if user presses a key then search starts and if user again presses key before iteration is over then iteration should stop and start from the begining as per what user typed. So how do i capture that event if the iteration does not end.

Please suggest something.
Feb 5 '09 #1
10 1598
acoder
16,027 Recognized Expert Moderator MVP
I would suggest, first of all, that you avoid a hidden table and use an object or array to store the data. This would avoid querying the DOM every time.
Feb 5 '09 #2
dmjpro
2,476 Top Contributor
is that late for DOM querying? ;)
Feb 6 '09 #3
acoder
16,027 Recognized Expert Moderator MVP
I'm not sure what you mean there.

In your original problem, you could use an object to deal with the manipulation of the data. It could have a variable which is used to indicate that the search should stop or continue which you can set to false when another key is pressed.
Feb 7 '09 #4
dmjpro
2,476 Top Contributor
Hey Acoder strange!
The same policy i tried to stop searching .. onKeyDown i am having the searching loop and onKeyPress i am having another handler to set the flag true or false. But i failed to manage the problem.
Have a look at my code.

Expand|Select|Wrap|Line Numbers
  1.             var prev_rolename = '';
  2.             var prev_roleDeptName = '';
  3.             var prev_roleDeptCode = '';
  4.             var prev_userName = '';
  5.             var prev_userDesgCode = '';
  6.             var prev_userDeptCode = '';
  7.  
  8.             var _break = false;
  9.  
  10.             function reArrnageList(){
  11.                 document.getElementById('MainDataDiv').style.display = 'block';
  12.                 document.getElementById('NoDataDiv').style.display = 'none';
  13.  
  14.                 var searchString = document.getElementById('searchString').value;
  15.                 var searchStringDesg = document.getElementById('searchStringDesg').value;
  16.                 var searchStringDeptCode = document.getElementById('searchStringDeptCode').value;
  17.  
  18.                 var dummmyTab = document.getElementById('DummyTable');
  19.                 var mainTab = document.getElementById('MainTable');
  20.                 for(var i=1;i<mainTab.rows.length;){mainTab.deleteRow(i);i=1;}
  21.                 for(var i=0;i<dummmyTab.rows.length;i++){
  22.  
  23.                     if(_break){_break=false;i=0;continue;}
  24.  
  25.                     var userName = dummmyTab.rows[i].cells[0].childNodes[1].value;
  26.                     var desgCode = dummmyTab.rows[i].cells[1].innerHTML;
  27.                     var deptCode = dummmyTab.rows[i].cells[2].innerHTML;
  28.                     if(searchString.length>userName.length)
  29.                         continue;
  30.                     //if(userName.toUpperCase().substr(0,searchString.length)==searchString.toUpperCase()){
  31.                     if(userName.toUpperCase().indexOf(searchString.toUpperCase())!=-1
  32.                        && desgCode.toUpperCase().indexOf(searchStringDesg.toUpperCase())!=-1
  33.                        && deptCode.toUpperCase().indexOf(searchStringDeptCode.toUpperCase())!=-1){
  34.                         var cloneRow = document.getElementById('userListTR_'+(i+1)).cloneNode(true);
  35.                         document.getElementById('HeaderRow').parentNode.appendChild(cloneRow);
  36.                     }
  37.                 }
  38.                 //document.getElementById('searchString1').focus();
  39.                 if(mainTab.rows.length==1){
  40.                     document.getElementById('MainDataDiv').style.display = 'none';
  41.                     document.getElementById('NoDataDiv').style.display = 'block';
  42.                 }
  43.             }
  44.  
  45.             function stopSearch(){
  46.                 var cur_userName = document.getElementById('searchString').value;
  47.                     var cur_userDesgCode = document.getElementById('searchStringDesg').value;
  48.                     var cur_userDeptCode= document.getElementById('searchStringDeptCode').value;
  49.                     var cur_rolename = parent.frames['roleWindow'].document.getElementById('searchString').value;
  50.                     var cur_roleDeptName = parent.frames['roleWindow'].document.getElementById('searchStringDept').value;
  51.                     var cur_roleDeptCode  = parent.frames['roleWindow'].document.getElementById('searchStringDeptCode').value;
  52.  
  53.                     if(prev_rolename!=cur_rolename || cur_roleDeptName!=prev_roleDeptName || cur_roleDeptCode!=prev_roleDeptCode
  54.                        || cur_userName!=prev_userName || cur_userDesgCode!=prev_userDesgCode || cur_userDeptCode!=prev_userDeptCode){
  55.                         prev_rolename = cur_rolename;
  56.                         prev_roleDeptName = cur_roleDeptName;
  57.                         prev_roleDeptCode = cur_roleDeptCode;
  58.                         prev_userName = cur_userName;
  59.                         prev_userDesgCode = cur_userDesgCode;
  60.                         prev_userDeptCode = cur_userDeptCode;
  61.                    }
  62.                 }
  63.  
Expand|Select|Wrap|Line Numbers
  1. <input type="text" name="searchString1" id="searchString1" onkeyup="document.getElementById('searchString').value=this.value;reArrnageList();" onkeydown="stopSearch()"/>
  2.  
Thanks!
Feb 9 '09 #5
acoder
16,027 Recognized Expert Moderator MVP
You could use return to stop processing the function.

By using a table, it will take longer, so you may still want to consider using a data structure (array or object).
Feb 9 '09 #6
dmjpro
2,476 Top Contributor
OK i will be fixing it soon and let you know ..hope the positive result will come ;)
Feb 9 '09 #7
dmjpro
2,476 Top Contributor
I am using Object Array ... Still it's not working ..it's working late than before .. :(
What is happening when the loop is getting processed then the Browser gets busy .. then it's no more able to process any signal .. that's why it's happening such ..But if the key getting pressed rapidly then how should i capture in my situation ... ;)
Feb 17 '09 #8
acoder
16,027 Recognized Expert Moderator MVP
Approximately how much data are we talking about here? Any chance you could provide a link?
Feb 17 '09 #9
dmjpro
2,476 Top Contributor
No chance of providing link... The question is not about how much Data.
The question is if somewhere machine stuck then can't it be stopped?
Feb 17 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1360
by: Joecx | last post by:
I am capturing the click event using Overrides OnClick. This captures the click event in the open or unused areas of the form, but it doesn't capture the click event in the textboxes etc. Do I have to program each text box to capture the click event or is there a way to capture all mouse events regardless of whether you click in the form...
3
4956
by: Greg | last post by:
I want to be able to capture the user pressing Ctrl+S. I know that the IE browser has a key binding for Ctrl+S but is there any way that I can be notified of this key press anyway. I have found tons of examples of capturing keys in IE but *none* of them work for capturing Ctrl+S, Ctrl+F, Ctrl+P,etc or any key combination that has a binding...
4
11991
by: Jay Xx | last post by:
I have an IFrame in design mode. I've tried a bunch of things to capture key presses in that IFrame, but I can't seem to get it. I can capture key presses outside the IFrame fine. I have this problem in Firefox, not IE. I do know it's possible because Blogger.com's rich text editor does it, but their code is cryptic and separated into like 20...
7
20364
by: jerrygarciuh | last post by:
Hello, I have been playing with various Googled solutions for capturing the <Enter> key to suppress form submission. My first question is whether anyone has a script that works in all common browsers? The script bellow is IE only. It fails FF 1.0 and NN 7. Also, if I can trap the keypress I would like to use it to tab to the next...
1
1427
by: Jonah Olsson | last post by:
Hello, I'm trying to build an "add-on" to an already existing custom web user control. The old control collects some user data and saves it to a database. The new control should collect some extra info from the user and add it to a new table in the database. The old control should not be re-written (at least not now..), so I need a way...
10
6001
by: Andrew | last post by:
Hi, I have a messagebox that pops up due to an event. I did it in javascript. ie. alert("Time's up. Assessment Ended"); I want to capture the OK and Cancel events of this alert messagebox. My code is in C#/ASP.NET. TIA. Andrew.
5
4726
by: Nick | last post by:
Hey guys, I have 2 events on a windows forms datagrid, the mouse move as well as the double click events. What's happening is that when I double click on a row in the grid, the mouse move event gets triggered and the double click is not identified at all. Is there any way I can invoke the double click when the mouse move also exists?
3
2029
by: Sujoan | last post by:
Hi, What is WMI? Is it possible to use WMI event to capture a Toolbar button click(using RSOP_IEToolbarButton object) from a DLL(A Browser Helper Object in my project)?If so,please provide me some help on this issue.. or pls help me out if any other alternative exists in capturing a button click event from a BHO in IE.. Thanks and Regards,...
2
4760
by: =?Utf-8?B?SmVzcGVyLCBEZW5tYXJr?= | last post by:
I have a tabcontrol where I want to capture the CTRL+C key combination. My tabcontrol has on its tabpages some treeView controls. My intention is to intercept the event of pressing the CTRL+C when one of the controls embedded in the tabControl has the focus. I'm doing this using the KeyDown event. However, when pressing the CTRL+C my computer...
7
2959
by: David Lozzi | last post by:
Howdy, I'm trying to capture the session end event. I put a spot of code in the Session_End event in the Global.asax.vb file. The function simply writes to a database table logging the event. I have the same function in the Session_Begin and the Application events. I am capturing the Session beginning and the App begin and end but no...
0
7918
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7843
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6621
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5713
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5392
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2353
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.