By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,480 Members | 1,766 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,480 IT Pros & Developers. It's quick & easy.

Strange behaviour of onkeydown

P: n/a
Hi,
I have small problem. What is wrong within this script ? It works on my
PC (IE6, IE7, FF) but doesn't work on other PCs with the same
configuration ? Any idea ?

function addPointOnTypingDate(field){
var f = document.getElementById(field);
f.onkeydown=function(e){
var e=window.event || e
if (e.keyCode != 8 && e.keyCode != 46) {
if (f.value.length == 2) {
f.value = (f.value + ".");
} else if (f.value.length == 5) {
f.value = (f.value + ".");
}
}
}
}
Thanks,
Roman
Jul 16 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Roman" <ro*************@gmail.comwrote in message
news:g5**********@news2.task.gda.pl...
Hi,
I have small problem. What is wrong within this script ? It works on my PC
(IE6, IE7, FF) but doesn't work on other PCs with the same configuration ?
Any idea ?

function addPointOnTypingDate(field){
var f = document.getElementById(field);
f.onkeydown=function(e){
var e=window.event || e
if (e.keyCode != 8 && e.keyCode != 46) {
if (f.value.length == 2) {
f.value = (f.value + ".");
} else if (f.value.length == 5) {
f.value = (f.value + ".");
}
}
}
}
Looks like strange behaviour to me, what are you trying to do ?

Aaron

Jul 20 '08 #2

P: n/a
Roman escribió:
Hi,
I have small problem. What is wrong within this script ? It works on my
PC (IE6, IE7, FF) but doesn't work on other PCs with the same
configuration ? Any idea ?

function addPointOnTypingDate(field){
var f = document.getElementById(field);
f.onkeydown=function(e){
var e=window.event || e
if (e.keyCode != 8 && e.keyCode != 46) {
if (f.value.length == 2) {
f.value = (f.value + ".");
} else if (f.value.length == 5) {
f.value = (f.value + ".");
}
}
}
}
I'd say that you call addPointOnTypingDate("foo") before defining <input
id="foo"(perhaps in the document head) so it works fine in your local
server but it stops working once you upload it to the internet and
network lag gets involved.

Make sure addPointOnTypingDate("foo") is not called until foo is loaded,
for instance:

window.onload=function(){
addPointOnTypingDate("foo");
}
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño Mar*a: http://www.demogracia.com
--
Jul 21 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.