Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 29th, 2005, 10:37 AM
Registered User
 
Join Date: Nov 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default odd FF error, IE does nothing when run.

I am working with some textboxes and JavaScript to give an excel like feel - when a user arrows over they are moved to a new textbox. I have some code that works in Firefox, but it does absolutely nothing in IE. Now in FF, there is an error that appears in the JavaScript console, which changes the line number based on which arrow a user presses, but again, IE does not even throw an error.


Error: [Exception... "'Permission denied to get property XULElement.selectedIndex' when calling method: [nsIAutoCompletePopup::selectedIndex]" nsresult: "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)" location: "JS frame :: file:///c:/Documents%20and%20Settings/bjb/Desktop/Javascript%20Keypress/Keypress1.html :: KeyCheck :: line 40" data: no]
Source File: file:///c:/Documents%20and%20Settings/bjb/Desktop/Javascript%20Keypress/Keypress1.html
Line: 40

Down is line 46, up is line 34. Left is 28 and right is 40, it does not matter which textbox I am in, the error lines are always the same.

I am not a JavaScript expert, but here is what I came up with. Any help would be appreciated!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>JavaScript key press event</title>
<script type="text/javascript">
//document.onkeyup = KeyCheck;

function KeyCheck(e,r)
{
   var KeyID = (window.event) ? event.keyCode : e.keyCode;
   var Textbox = r.name;
   var Row = Textbox.charAt(4);
   var Col = Textbox.charAt(5);
   var NewTextbox = "text";
   switch(KeyID)
   {
      case 37: //left
      Col--;
      NewTextbox = NewTextbox + Row + Col
      eval("document.Form1." + NewTextbox + ".focus()");
      break; // line 20

      case 38://up
      Row--;
      NewTextbox = NewTextbox + Row + Col
      eval("document.Form1." + NewTextbox + ".focus()");
      break;

      case 39://right
      Col++;
      NewTextbox = NewTextbox + Row + Col
      eval("document.Form1." + NewTextbox + ".focus()");
      break;

      case 40://down
      Row++;
      NewTextbox = NewTextbox + Row + Col
      eval("document.Form1." + NewTextbox + ".focus()");
      break;
   }// line 40
}
</script>
</head>
<body>
<form name="Form1">
Press the arrow keys on your keyboard.

<table width="300" border="0">
  <tr>
    <td>Mon</td>
    <td>Tues</td>
    <td>Wed</td>
    <td>Thurs</td>
    <td>Fri</td>
    <td>Sat</td>
    <td>Sun</td>
  </tr>
  <tr>
    <td><input name="text11" type="text" size="6" maxlength="6" onkeypress="return KeyCheck(event,this);"></td>
    <td><input name="text12" type="text" size="6" maxlength="6" onkeypress="return KeyCheck(event,this);"></td>
    <td><input name="text13" type="text" size="6" maxlength="6" onkeypress="return KeyCheck(event,this);"></td>
    <td><input name="text14" type="text" size="6" maxlength="6" onkeypress="return KeyCheck(event,this);"></td>
    <td><input name="text15" type="text" size="6" maxlength="6" onkeypress="return KeyCheck(event,this);"></td>
    <td><input name="text16" type="text" size="6" maxlength="6" onkeypress="return KeyCheck(event,this);"></td>
    <td><input name="text17" type="text" size="6" maxlength="6" onkeypress="return KeyCheck(event,this);"></td>
  </tr>
  <tr>
    <td><input name="text21" type="text" size="6" maxlength="6" onkeypress="return KeyCheck(event,this);"></td>
    <td><input name="text22" type="text" size="6" maxlength="6" onkeypress="return KeyCheck(event,this);"></td>
    <td><input name="text23" type="text" size="6" maxlength="6" onkeypress="return KeyCheck(event,this);"></td>
    <td><input name="text24" type="text" size="6" maxlength="6" onkeypress="return KeyCheck(event,this);"></td>
    <td><input name="text25" type="text" size="6" maxlength="6" onkeypress="return KeyCheck(event,this);"></td>
    <td><input name="text26" type="text" size="6" maxlength="6" onkeypress="return KeyCheck(event,this);"></td>
    <td><input name="text27" type="text" size="6" maxlength="6" onkeypress="return KeyCheck(event,this);"></td>
  </tr>
  <tr>
    <td><input name="text31" type="text" size="6" maxlength="6" onkeypress="return KeyCheck(event,this);"></td>
    <td><input name="text32" type="text" size="6" maxlength="6" onkeypress="return KeyCheck(event,this);"></td>
    <td><input name="text33" type="text" size="6" maxlength="6" onkeypress="return KeyCheck(event,this);"></td>
    <td><input name="text34" type="text" size="6" maxlength="6" onkeypress="return KeyCheck(event,this);"></td>
    <td><input name="text35" type="text" size="6" maxlength="6" onkeypress="return KeyCheck(event,this);"></td>
    <td><input name="text36" type="text" size="6" maxlength="6" onkeypress="return KeyCheck(event,this);"></td>
    <td><input name="text37" type="text" size="6" maxlength="6" onkeypress="return KeyCheck(event,this);"></td>
  </tr>
</table>
</form>

</BODY>
</HTML>

 
Old November 29th, 2005, 12:55 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

I don't think IE raises the onkeypress event for the arrow keys, if you change onkeypress for onkeydown it should work fine.

IMHO it would also be wise to use:
Code:
document.Form1[NewTextbox].focus();
Instead of:
Code:
eval("document.Form1." + NewTextbox + ".focus()");
To avoid the overhead of using eval()

HTH,

Chris

 
Old November 29th, 2005, 01:05 PM
Registered User
 
Join Date: Nov 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks chris, I will make the change to the brackets and the keydown is working like a charm. The firefox error is actually a known bug. https://bugzilla.mozilla.org/show_bug.cgi?id=236791

I added the line autocomplete="OFF". This does have the side effect that all the textboxes are cleared when refreshing the screen... I'll have to double check if that is desired or not.

 
Old November 29th, 2005, 01:37 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Wasn't aware of that bug...

If you need to get autocomplete behaviour and get around the bug, you could store copies of the values in hidden fields, then populate the boxes from the hidden fields when your page loads.

 
Old November 29th, 2005, 01:50 PM
Registered User
 
Join Date: Nov 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hmm, not a bad idea.

The data entry app Im working on should be partly filled out from a db, so a refresh might clear changes they've made. That could be more problematic then I originally thought. Then again it might be something where I am able to do everything with only the one inital load of the page and then use dhtml and layers and keep it from reloading.

Course we are still in the design phase, I just wanted to see how difficult this would be =)

Thanks again!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Query Error & Run-Time Error 3022 DavidWE Access 1 July 31st, 2008 11:17 AM
Odd InputBox error Archdeacon VBScript 3 June 15th, 2008 10:50 PM
odd error with apply-templates select="..." name Fitty XSLT 1 January 18th, 2008 03:45 AM
Works in IE but not in FF sofiacole Pro JSP 1 September 12th, 2007 11:20 PM
Odd arithmetic overflow error.... 7racer SQL Server 2000 4 May 12th, 2006 09:17 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.