Forum Moderators: open

Message Too Old, No Replies

firefox & event (help me please)

         

daywalker

6:10 am on Oct 26, 2007 (gmt 0)

10+ Year Member



HELLO everyone

Mycode:

function checkKey(form) {
if (form.x1.value.length==6)
form.x2.focus();

key = event.keyCode;

if (key==13 ¦¦ key==0) {
if (form.x0.value.length <= 1) {
alert("enter name");
form.x0.focus();
return;
}
if (form.x1.value.length!= 6 ¦¦ form.x2.value.length!= 7) {
alert("enter number");
form.x1.focus();
return;
}
if (checkxumin(form.x1.value,form.x2.value)==false) {
alert("try again");
form.x1.focus();
return;
}
form.submit();
}

___________________________________

IE & Opera works fine..
but firefox says:
"event is not defined"
key = event.keyCode;

any idea? please help me i'm a newbie

thank you
have a good day

lavazza

6:19 am on Oct 26, 2007 (gmt 0)

daywalker

6:32 am on Oct 26, 2007 (gmt 0)

10+ Year Member



thank you lavazza
but could you modify this script for newbie?
I would really appreciate all the help

daveVk

7:07 am on Oct 26, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please show code where checkKey is being called from, you will need to get event object prior to the call. Assume called from the event handler (onkeypress maybe).

daywalker

7:21 am on Oct 26, 2007 (gmt 0)

10+ Year Member



<SCRIPT type='text/javascript'>
<!--
function goFocus() {
document.form1.x0.focus();
}

function checkxumin(xumin1, xumin2) {
var i, sum = 0;
var str = xumin1 + xumin2;

if (parseInt(xumin2) < 1000000 && parseInt(xumin2) > 4999999)
return false;

for (i=0,sum=0; i<12; i++)
sum += (((i%8) + 2) * (str.charAt(i) - "0"));

if (((11 - (sum % 11)) % 10) == str.charAt(12))
return true;

return false;
}

function checkKey(form) {
if (form.x1.value.length==6)
form.x2.focus();

key = event.keyCode;

if (key==13 ¦¦ key==0) {
if (form.x0.value.length <= 1) {
alert("enter name");
form.x0.focus();
return;
}
if (form.x1.value.length!= 6 ¦¦ form.x2.value.length!= 7) {
alert("enter number");
form.x1.focus();
return;
}
if (checkxumin(form.x1.value,form.x2.value)==false) {
alert("try again");
form.x1.focus();
return;
}
form.submit();
}
}
//-->
</SCRIPT>
</HEAD>
<BODY onload="goFocus()">

<FORM name=form1 action="login.php" method=post>
<TABLE width="350" border="0" cellpadding="0" cellspacing="6" bgcolor="#F2F3F3">
<TR>
<TD align="right">
name
</TD>
<TD>
<INPUT size=6 name=x0 maxlength=4 type=text>
</TD>
</TR>
<TR>
<TD align="right">
number
</TD>
<TD>
<INPUT size=6 maxlength=6 name=x1 type=text onKeyUp="checkKey(this.form)"> - <INPUT size=9 maxlength=7 name=x2 type=password onKeyDown="checkKey(this.form)">
</TD>
</TR>
<TR>
<TD align="center" height="30" colspan="2">
<INPUT type=button value="send" onClick="checkKey(this.form)">
</TD>
</TR>
</TABLE>
</FORM>


__________________________________________

Here is the whole script I'm having problems with
it's very difficult for me

Big thanky you!

daveVk

8:01 am on Oct 26, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<INPUT size=6 maxlength=6 name=x1 type=text onKeyUp="checkKey(this.form,event)">

..

<INPUT type=button value="send" onClick="checkKey(this.form,event)">

..

function checkKey(form,iEv) {
if (form.x1.value.length==6)
form.x2.focus();

var evt
if ( typeof window.event!= "undefined" ) { evt = window.event; }
else { evt = iEv; }
var key = (evt.charCode)? evt.charCode :((evt.which)? evt.which : evt.keyCode);

..

daywalker

8:39 am on Oct 26, 2007 (gmt 0)

10+ Year Member



Dear daveVk

it does not work properly.
fifefox Error Console shows some messages :
"evt has no properties"

var key = (evt.charCode)? evt.charCode :((evt.which)? evt.which : evt.keyCode);

Anyway, Big thank you for your kind help.
Have a good time

daveVk

9:55 am on Oct 26, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Missed this one

<INPUT size=9 maxlength=7 name=x2 type=password onKeyDown="checkKey(this.form,event)">

If that dont work feel free to post your current version.

daywalker

9:24 pm on Oct 26, 2007 (gmt 0)

10+ Year Member



daveVK Thank you for all your help

it's strange it only works when using with pressing key ' enter '
On clicking the button 'send' no return alert popup

What should I do?
I'm sorry to bother you again.....

daveVk

11:58 pm on Oct 26, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



turn this part into separate function

function checkSubmit(form){
if (form.x0.value.length <= 1) {
alert("enter name");
form.x0.focus();
return;
}
if (form.x1.value.length!= 6 ¦¦ form.x2.value.length!= 7) {
alert("enter number");
form.x1.focus();
return;
}
if (checkxumin(form.x1.value,form.x2.value)==false) {
alert("try again");
form.x1.focus();
return;
}
form.submit();
}

call it here

if (key==13 ¦¦ key==0) { checkSubmit(form); }

and here

<INPUT type=button value="send" onClick="checkSubmit(this.form)">

daywalker

1:38 am on Oct 27, 2007 (gmt 0)

10+ Year Member



Hello,Dear daveVk
finally,it Works fantastic! Exactly what I expected
I want to thank you again for your incredible kindness.
God bless you!
have a good day