473,785 Members | 2,291 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Keypress irregularity: IE vs. FF function call timing?

Hello,

I am programming a little game, and I want the focus to move from one
input box to the next as the user types. I have image-input pairs so
the user is typing a letter under a picture. (Similar to word jumbles
or cryptograms.) I'm also keeping track of the user's complete guess
in a cookie so they can save their game. I get the input; if it's a
letter, I capitalize it and update the cookie; then move the focus to
the next input box. It works as I expect in FF, but not in IE.

In IE, it just capitalizes the letter, but won't move the focus. Now,
if I comment out the cookie handling section or type a number, it will
update the current input box, move to the next, and put in the user's
input (numbers, lowercase letters, etc) there too. So something must
be happening in the cookie handling section, although it works as
expected and the JavaScript Console doesn't display any errors or
warnings.

I'm wondering if the JavaScript run-time is somehow not finishing
everything before it calls the last line, MoveFocus(). BTW, I've tried
putting MoveFocus() in the onchange= attribute but it was never
triggered. I guess keypress + updating the value doesn't count as a
change.

Thanks for any hints, debugging, or insight you can provide.

HTML:
<div class="pair">
<img id="q1" src="img.jpg" alt="image" class="black" />
<br />

<input id="u1" type="text" class="guess" size="1" maxlength="1"
value=""
onFocus="Highli ght(this);" onBlur="UnHighl ight(this);"
onKeyPress="Rep laceVal(event); " />
</div>

javascript:
function MoveFocus( objid )
{
var id = objid.slice( 1 );
id++;
document.getEle mentById( "u"+id ).focus();
return true;
}

function ReplaceVal(e)
{
// Update interface
var keynum;
var numcheck;
var obj;

// Get the value of the user's input
if(window.event ) // IE
{
keynum = e.keyCode;
obj = e.srcElement;
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which;
obj = e.target;
}
var keychar = String.fromChar Code(keynum)

// Ignore numbers and punctuation
recheck = /[a-zA-Z]/;
if( !recheck.test( keychar) )
{ obj.value = ' '; }
else
{
obj.value = keychar.toUpper Case();

// Find the guess cookie
var oldguess;
var ca = document.cookie .split(';');
for(var i=0;i < ca.length;i++)
{
var c = ca[i];
var pair = c.split('=');
if( pair[0] == 'guess' )
{
oldguess = pair[1];
break;
}
}

// Update the cookie
var lind = obj.id.slice(1) ;
var newguess = oldguess.slice( 0, lind) + obj.value +
oldguess.slice( lind+1 );
document.cookie = 'guess='+newgue ss+';';
}

MoveFocus( obj.id );
return true;
}

Jun 17 '06 #1
1 2046
Well, there were errors in the cookie section. I was thinking PHP and
forgot the second argument for slice. Fixing that error was one of many
iterations. Working Javascript function follows:
function ReplaceVal(e)
{
var keynum;
var numcheck;
var obj;

// Get the value of the user's input
if(window.event ) // IE
{
keynum = e.keyCode;
obj = e.srcElement;
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which;
obj = e.target;
}
var keychar = String.fromChar Code(keynum)

// Ignore numbers and punctuation
recheck = /[a-zA-Z]/;
if( !recheck.test(k eychar) )
{
obj.value = '';
}
else
{
obj.value = keychar.toUpper Case();

// Update the cookie
var oldguess = getCookie( "guess" );

if( oldguess )
{
var lind = obj.id.slice(1) ;
var preslice = oldguess.substr ing(0,lind);
var postslice = oldguess.substr ing( ++lind, oldguess.length );

var newguess = preslice+obj.va lue+postslice;
setCookie("gues s", newguess );
}
}

MoveFocus( obj.id );
}

Jun 19 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
43955
by: Roland Hall | last post by:
Is there a way to return multiple values from a function without using an array? Would a dictionary object work better? -- Roland Hall /* This information is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. */ Technet Script Center - http://www.microsoft.com/technet/scriptcenter/ WSH 5.6 Documentation -...
3
9123
by: Hamish | last post by:
I am trying to detect the up and down keys on a key press function, but they do not seem to generate a keypress call. Is there another event generated when these keys are pressed Thanks. PS Apologies if this appears as a double post, but the news server I used originally does not seem to propagate most other news servers.
11
3258
by: srkkreddy | last post by:
Hi, I have written a large program which makes multiple calls to number of functions (also written by me) of the program. Now, I want to know the collective time taken by all the calls to a specific function. Is there any way I can find this time. Thanks in advance, Raja Kiran Sandireddy.
3
8546
by: Raul M. Colon | last post by:
Is possible to assign a click event to a button control in a Web form just pressing the return key? Something like windows forms where you can assign this action to a default control. For example, if I press Return, I want to fire the button_click event even when the button is not in focus. Any thoughts? Thanks! Raul
4
4533
by: Tom | last post by:
I have a VB.NET user control that I wrote - this control has three or four other controls on it (textbox, combobox, datetime picker, etc). Now, whenever the control is on a form and the user enters anything into the textbox (for instance) I trap the keypress event to handle some stuff (i.e. if it is an enter key, etc). Now, once I am done with handling the keypress event for the textbox, I then need to pass that keypress event BACK to the...
3
6864
by: Fia | last post by:
Hi In Visual Basic 6 I could call keypress with an integer of a choosen key. For example I could call a textbox's keypress with the number 13 (for the enter key). But now in Visual Basic .Net I don't know how I shall do to do the same thing. I have tried to send Keys.Numpad8, but then it complains about it cannot convert from Keys to keyEventArgs I have also tried to send the number 8, but then it complains it cannot convert from Integer...
2
3307
by: Steven D'Aprano | last post by:
The timeit module is ideal for measuring small code snippets; I want to measure large function objects. Because the timeit module takes the code snippet argument as a string, it is quite handy to use from the command line, but it is less convenient for timing large pieces of code or when working in the interactive interpreter. E.g. variations on this *don't* work: $ python Python 2.4.3 (#1, Jun 13 2006, 11:46:08)
11
1986
by: The Frog | last post by:
Hi all, Maybe I am just missing something simple here, but I seem to have an issue with a callback function in A97 that is used to fill a Listbox with values. The first time the callback function is used (when the form opens) all runs well and everyone is happy. Then comes the problem - values are added to the recordset (ADO) that the callback function uses to populate the listbox. After the new values are added to the recordset, the...
2
19297
by: Tony Johansson | last post by:
Hello! I have created a Control that consist of a label and a textbox.I have called this class ctlLabelTextbox. public partial class ctlLabelTextbox : UserControl { .... } The class that I have created for this purpose is derived from class UserControl.
0
9647
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9491
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10357
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10104
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8988
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4063
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
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.