473,385 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Select function not working when called on onKeyDown evnt

2
I am trying to select some text in a texbox , on keyDown event.

but when i write such simple code its not selecting the text in that textbox ,
instead its only focusing that textbox.

It selects the same when called on keyUp event.
But its my application need that it should get called on keyDown event.

Please provide help , if possible
Thnks,
Ravi
Nov 7 '06 #1
3 3815
AricC
1,892 Expert 1GB
What's the code?
Nov 7 '06 #2
ravip
2
What's the code?
Expand|Select|Wrap|Line Numbers
  1. // This is the function being called on onKeyDown event in a textBox
  2. // The application has got a grid of textboxes , and this function is created to  
  3. // move through these textboxes on arrow key press.(left , right ....)
  4. function TabNext( obj,event,len,next_field ) 
  5. {
  6.     var keycode = event.keyCode; 
  7.     var headerTable = document.getElementById( 'tblHead' );
  8.     var HeaderTableRow = headerTable.cells;
  9.     var maxColumns = HeaderTableRow.length;
  10.  
  11.     var rowsInTable = obj.parentNode.parentNode.parentNode.rows;
  12.     var maxRows = rowsInTable.length;
  13.  
  14.     var cellIndex = obj.parentNode.cellIndex;
  15.     var rowNo = obj.parentNode.parentNode.rowIndex;    
  16.  
  17.     var rowIndex=obj.parentNode.parentNode.rowIndex;
  18.  
  19. if(keycode == 37)//LEFT
  20.  {         
  21.    if(caretPos(obj) == 1 || obj.value == "")
  22.     {
  23.     while(cellIndex > 1)
  24.  {
  25.     cellIndex = cellIndex - 1;
  26.   neighbourElement = HeaderTableRow[cellIndex].id;        
  27. if(document.getElementById( neighbourElement + rowIndex).readOnly == false )
  28. {
  29. //THIS IS THE POINT WHERE I WANT TO SHOW THE TEXT TO BE SELECTED .
  30.  
  31. document.getElementById( neighbourElement + rowIndex).select();     break;
  32. }
  33. }
  34. }
  35. }
  36.     if(keycode == 39)//RIGHT
  37.     {         
  38.        if(caretPos(obj) == -1)
  39.        {       
  40.                while(cellIndex < (maxColumns-1) )
  41.                {
  42.                 cellIndex = cellIndex + 1;
  43.                    neighbourElement = HeaderTableRow[cellIndex].id;        
  44.                    if(document.getElementById( neighbourElement + rowIndex).readOnly == false )
  45.                    {
  46.                        document.getElementById( neighbourElement + rowIndex).select();
  47.                        break;
  48.                    }
  49.                 }
  50.         }
  51.     }
  52.  
  53.     if(keycode == 38)//UP    
  54.     {     
  55.         while(rowIndex > 0)        
  56.         {   
  57.                neighbourElement = HeaderTableRow[cellIndex].id;           
  58.                rowIndex = rowIndex - 1;
  59.                if(document.getElementById( neighbourElement + rowIndex).readOnly == false )
  60.                {
  61.                    document.getElementById( neighbourElement + rowIndex).select();
  62.                    break;
  63.                }
  64.            }
  65.     }
  66.  
  67.     if(keycode == 40)//DOWN    
  68.     {            
  69.         while(rowIndex < ( maxRows - 1 ) )    
  70.        {    
  71.              neighbourElement = HeaderTableRow[cellIndex].id;    
  72.                rowIndex = rowIndex + 1;    
  73.                if(document.getElementById( neighbourElement + rowIndex).readOnly == false)
  74.                {
  75.                    document.getElementById( neighbourElement + rowIndex).select();
  76.                    break;
  77.                }
  78.            }
  79.     }
  80.  
Nov 8 '06 #3
iam_clint
1,208 Expert 1GB
Please post the html that goes with it so i can do some testing and post you the fixed code.
Nov 8 '06 #4

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

Similar topics

4
by: J. VerSchave | last post by:
I am curious if there is a way to handle this... maybe with Javascript... Is there a way to set a TEXTAREA field so that the tab key on the user's keyboard will create a tab within the text...
14
by: xxbmichae1 | last post by:
I have a <select> object that i've set up an onchange event that fires in IE fine when I use the cursor up and down in the list, but If I use the cursor up and down in Firefox the event doesn't...
6
by: Ken Foster | last post by:
Is it possible to return a class (not an instance of a class) from a function? For example (actually tried this code, it didn't work, but it's what I want sort of): Class EventMessage Public...
5
by: JHNielson | last post by:
I have a somewhat simple question, but have been baffled by it for a while, and now I'm on a tight deadline - have to get it done within 24 hours. I am trying to export a set of files to my hard...
1
by: sjarmy | last post by:
I am using javascript to make a dropdownlist act like a combobox and it is work well. The issue I'm having is when the user types in the combobox and finds the selection he wants, he has to use the...
25
by: bonneylake | last post by:
Hey Everyone, Well i am not sure if my question needs to be here or in coldfusion. If i have my question is in the wrong section i am sorry in advance an will move it to the correct section. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.