473,700 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.captur eEvents(Event.K EYDOWN);
}

document.onkeyd own = myKeyDown;

function myKeyDown(e){

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

var theform;
if (window.navigat or.appName.toLo werCase().index Of("netscape") > -1) {
theform = document.forms["Form1"];
}
else {
theform = document.Form1;
}

if ((mykey==13) && (posted==false) && (theform.btnSen d.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 6185
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.captur eEvents(Event.K EYDOWN);
}

document.onkeyd own = myKeyDown;

function myKeyDown(e){

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

var theform;
if (window.navigat or.appName.toLo werCase().index Of("netscape") > -1) {
theform = document.forms["Form1"];
}
else {
theform = document.Form1;
}

if ((mykey==13) && (posted==false) && (theform.btnSen d.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.c om...
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.captur eEvents(Event.K EYDOWN);
}

document.onkeyd own = myKeyDown;

function myKeyDown(e){

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

var theform;
if (window.navigat or.appName.toLo werCase().index Of("netscape") > -1) {
theform = document.forms["Form1"];
}
else {
theform = document.Form1;
}

if ((mykey==13) && (posted==false) && (theform.btnSen d.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
17253
by: Csaba2000 | last post by:
I want to be able to programatically click on the center of an <INPUT type=image ...> element (I only care about IE 5.5+). This should work regardless of whether IE has focus. Normally you would do myDomElement.click and the mouse doesn't matter, but in the case of an input image element, what happens is the submitted url has something like "?x=12&y=7" appended to it (the numbers vary per mouse position on the clicked element). If you hit...
6
5677
by: Adrian | last post by:
I need to have 2 submit buttons in one form calling the same page. I just need to know which was used. Being able to pass a hidden form input for each would be ideal. How can I do this?? Thanks!,Adrian
3
12928
by: Ben | last post by:
Here's my form: <form name="aForm" method='post'> <input type=file name=file1 onkeypress='KeyPress()'><br> <a id='attachMoreLink' href='javascript:AddFileInput()">Attach More Files </a> <input type=submit value='Done'> </form>
17
2196
by: Bill Grigg | last post by:
I have been successfully calling DLL's using VC++ 6.0 and also using VC++7.1 (.NET). I only mention this because I have never felt comfortable with the process, but nonetheless it did work. Recently I started calling an unmanaged DLL from a .NET app. It worked fine. Now I have the situation where I am trying to call a function in one DLL from another DLL. Both are unmanaged and are built with VC++7.1. In the calling DLL I set the property...
2
2081
by: HVG | last post by:
Hi, does anyone know why using ".click()" on a <INPUT type="file"> control should be a problem? - the html file selction control is on a very plain webform page with just the <input type="file"> control and a submit button. - the ".click()" method is simply used to automatically open the file selction dialog box so the user doesn't have to click "Browse". (likewise the form is automatically submitted when the user selects a file). The...
15
4770
by: Nathan | last post by:
I have an aspx page with a data grid, some textboxes, and an update button. This page also has one html input element with type=file (not inside the data grid and runat=server). The update button will verify the information that has been entered and updates the data base if the data is correct. Update will throw an exception if the data is not validate based on some given rules. I also have a custom error handling page to show the...
1
1751
by: firenet | last post by:
21 function js_reply_msg(node,g_id,u_id,par_id) 22 { 23 node.innerHTML="<FORM><TEXTAREA name=\"msg_con\"><\/TEXTAREA><br><INPUT type=\"submit\" value=\"reply\"><\/FORM>" 24 node.nextSibling.nextSibling.innerHTML="" 25 } My thought is that when i clicked a link,the js function generate the Form,then get the input and deal with it.
7
7186
by: ero | last post by:
Is it possible to input values into a web form from an external source like a client-side javascript? There is a web site that I'm viewing where I have to enter 5 values in the form. 4 of the values don't change only one input field does. Is it possible to create a javascript to run which would popluate the non-changing values by executing the script or by pressing a button on the script? No experience at this so any examples would...
2
3480
by: johnlim20088 | last post by:
Hi Can anyone help me? I have a Javascript function in my test.aspx as follow:- <script language="Javascript"> function confirm_save() { if (confirm("Are you sure you want to save this changed?")==true) return true;
0
8731
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
8648
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
9218
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...
0
9081
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8975
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,...
1
6564
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4660
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2395
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2031
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.