472,122 Members | 1,439 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

calling input button click manually

CW
In my javascript, when enter key is pressed, I want to simulate the effect
of clicking a button.

var mykey;
var posted=false;

if (window.Event){
document.captureEvents(Event.KEYDOWN);
}

document.onkeydown = myKeyDown;

function myKeyDown(e){

if (window.Event){
mykey = e.which;
}
else{
mykey = event.keyCode;
}
//alert(mykey);

var theform;
if (window.navigator.appName.toLowerCase().indexOf("n etscape") > -1) {
theform = document.forms["Form1"];
}
else {
theform = document.Form1;
}

if ((mykey==13) && (posted==false) && (theform.btnSend.click))
{
posted=true;
theform.btnSend.click();
}
}

Everything works fine in IE4 to IE6. But NS behaviour is really bizzare.

Thing work as expected in NS7.

In NS6, theform.btnSend.click() does not cause form submission.

In NS4, it complains that theform.btnSend.click() does not exist (despite
having passed the if test that verifies theform.btnSend.click exists).

Any idea?

Thanks
Jul 23 '05 #1
3 6109
Lee
CW said:

In my javascript, when enter key is pressed, I want to simulate the effect
of clicking a button.

var mykey;
var posted=false;

if (window.Event){
document.captureEvents(Event.KEYDOWN);
}

document.onkeydown = myKeyDown;

function myKeyDown(e){

if (window.Event){
mykey = e.which;
}
else{
mykey = event.keyCode;
}
//alert(mykey);

var theform;
if (window.navigator.appName.toLowerCase().indexOf("n etscape") > -1) {
theform = document.forms["Form1"];
}
else {
theform = document.Form1;
}

if ((mykey==13) && (posted==false) && (theform.btnSend.click))
{
posted=true;
theform.btnSend.click();
}
}

Everything works fine in IE4 to IE6. But NS behaviour is really bizzare.

Thing work as expected in NS7.

In NS6, theform.btnSend.click() does not cause form submission.

In NS4, it complains that theform.btnSend.click() does not exist (despite
having passed the if test that verifies theform.btnSend.click exists).

Any idea?


It's generally a bad idea to do anything as drastic as submit a
form on keydown. That leaves the keyup event in limbo, with
unpredictable consequences.

I don't have NS6 installed, but NS4 submits for me when the button's
click() method is called.

Is there a reason why you're calling the click() method, instead of
just directly invoking the form's submit() method?

Jul 23 '05 #2
CW
because there are 2 buttons on the form. If I call submit, it doesn't
specify which button is pressed.

thanx
"Lee" <RE**************@cox.net> wrote in message
news:ck*********@drn.newsguy.com...
CW said:

In my javascript, when enter key is pressed, I want to simulate the effect
of clicking a button.

var mykey;
var posted=false;

if (window.Event){
document.captureEvents(Event.KEYDOWN);
}

document.onkeydown = myKeyDown;

function myKeyDown(e){

if (window.Event){
mykey = e.which;
}
else{
mykey = event.keyCode;
}
//alert(mykey);

var theform;
if (window.navigator.appName.toLowerCase().indexOf("n etscape") > -1) {
theform = document.forms["Form1"];
}
else {
theform = document.Form1;
}

if ((mykey==13) && (posted==false) && (theform.btnSend.click))
{
posted=true;
theform.btnSend.click();
}
}

Everything works fine in IE4 to IE6. But NS behaviour is really bizzare.

Thing work as expected in NS7.

In NS6, theform.btnSend.click() does not cause form submission.

In NS4, it complains that theform.btnSend.click() does not exist (despite
having passed the if test that verifies theform.btnSend.click exists).

Any idea?


It's generally a bad idea to do anything as drastic as submit a
form on keydown. That leaves the keyup event in limbo, with
unpredictable consequences.

I don't have NS6 installed, but NS4 submits for me when the button's
click() method is called.

Is there a reason why you're calling the click() method, instead of
just directly invoking the form's submit() method?

Jul 23 '05 #3
Lee
CW said:

because there are 2 buttons on the form. If I call submit, it doesn't
specify which button is pressed.


You can set a hidden form field to tell which was pressed,
or better, redesign it so that it will work without Javascript,
for those who have it disabled.

Please don't top post. Respond *after* the message you're
responding to.

Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Adrian | last post: by
17 posts views Thread by Bill Grigg | last post: by
7 posts views Thread by ero | last post: by
reply views Thread by leo001 | last post: by

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.