473,656 Members | 2,776 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

OnClick event of a button not called ....

Hi All,

I have a strange problem. I have 2 text boxes and a button in my form. There
is a function called on onchange event of the first text box. There is
another function called on onclick event of the button. Things work fine if
you move from one field to another using tab keys. But if you change
something in the first text box and move to button using mouse, the onchange
event of the text box is called but the onclick event of the button is not
called.

Any help regarding this will be highly appreciated.

Below is my code:

<html>
<head>

<script type="text/javascript">

function myfunction1()
{
alert("Text Box")
}

function myfunction()
{
alert("Button button")
}

</script>

</head>
<body>
<form name = "myform" >
Some text
<input type = "text" name = "txtname" onchange = "myfunction1()" >
<P>
Some text
<input type = "text" name = "txtname2" >
<P>
<input type="button" name = "btnsubmit"
onclick="myfunc tion()"
value="Call function">

</form>
</body>
</html>

Thank you,

Vinita

Jul 23 '05 #1
2 3403

Vinita Sharma <sh******@mail. armstrong.edu> wrote in message
news:cq******** **@news.armstro ng.edu...
Hi All,

I have a strange problem. I have 2 text boxes and a button in my form. There is a function called on onchange event of the first text box. There is
another function called on onclick event of the button. Things work fine if you move from one field to another using tab keys. But if you change
something in the first text box and move to button using mouse, the onchange event of the text box is called but the onclick event of the button is not
called.

Any help regarding this will be highly appreciated.

I think the calls to alert() are perturbing things here.
If you change your functions as shown, you can use the title bar and status
line to display the result for each event simultaneously, without altering
the html.
You should see a response to both events.

function myfunction1()
{
document.title= "Text Box";
setTimeout('doc ument.title=""' ,1000);
}

function myfunction()
{
window.status=" Button"
setTimeout("win dow.status=''", 1000);
}

Jul 23 '05 #2
Vinita Sharma wrote:
Hi All,

I have a strange problem. I have 2 text boxes and a button in my form. There
is a function called on onchange event of the first text box. There is
another function called on onclick event of the button. Things work fine if
you move from one field to another using tab keys. But if you change
something in the first text box and move to button using mouse, the onchange
event of the text box is called but the onclick event of the button is not
called.

Any help regarding this will be highly appreciated.
[...]

All the following scenarios are on Mac:

In Safari, exactly the opposite occurs. If you change the text box
then click on the button, only the onclick runs because the text box
never loses focus, so the onchange doesn't fire. However, if the
input button is a submit, then the onchange will fire provided the
button onclick returns true.

IE fires them sequentially, first the button onclick blocks, then the
text onchange when you click on OK. However, if the input button is
changed to a submit, no blocking occurs and two alerts result.

Firefox fires the text onchange first but without blocking, so you get
two alert boxes, with the button alert on top. Same again if the
button is a submit.

So the result could be described as 'unreliable' due browser vagaries
beyond your control.

What do you *want* to happen? If you are trying to validate a field,
make the button a submit button. Add an onclick to validate the form
content and if it fails, return false so the submit is canceled,
otherwise return true. And then validate again at the server 'cos the
user may have JavaScript turned off or may have circumvented your
validation some other way.

Incidentally, I'd get rid of spaces in tag attributes and your form
should have an action, even if it's "":
<form name = "myform" >


should be:

<form name="myform" action="" >
Have a happy new year! :-p

--
Fred
Jul 23 '05 #3

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

Similar topics

2
18564
by: RobG | last post by:
I am trying to dynamically add an onclick to an element, however I just can't get the syntax right. consider the following function: function doClick (evt,x) { // do things with evt and x } Which is called statically by: <button onclick="doClick(event,this);">Click me</button>
4
2258
by: RobG | last post by:
I have a function whose parameter is a reference the element that called it: function someFunction(el) { ... } The function is assigned to the onclick event of some elements in the HTML source:
5
7051
by: Tamir Khason | last post by:
How I can paint something onClick event? I need PaintEventArgs event in order to paint and raise Graphics, but onClick I have only EventArgs Event... Thanx
3
7716
by: Arulraja | last post by:
Hello, I have created 2 custom server controls, The parent custom control contains multiple child custom controls. The Child control has a button on it. If I Click the button control, it calls the Parent controls CreateChildControls() method before calling the child control's button click event. Because of this behaviour, I am not getting the changes I made in the
5
2576
by: moondaddy | last post by:
I have a <a> element in a datagrid which wraps some asp.net labels. this element also has an onclick event which does not fire in netscape 6 (and perhaps other browsers for all I know...). Below is the code for this. the onclick event calls a javascript function which I put an alert in the firt line to tell me if its working. It does work in IE. Any ideas on how to get netcrap... oops, I'm sorry, netscape to fire the onclick event? ...
3
2460
by: wardy1975 | last post by:
Hi all....looking for a bit of help here....I'm using an asp.net server side button, and trying to add an onclick event on the button to call a javascript function. However, I am trying to enter the onclick syntax directly in the html instead of via the attributes.add functionality (this is required due to the dynamic nature of how the buttons are added to the screen). The problem is, I get a compilation error when I try to load the page...
4
13549
by: sameergn | last post by:
Hi, I have an image in my HTML form which has onclick() handler. There is also a submit button and a text box. Whenever text box has focus and user presses enter, the onclick() event of image is fired with event.keyCode as undefined. I was expecting that the form would get submitted. I tried returning from onclick() handler if keyCode is null, but the
2
7707
by: bay_dar | last post by:
Hi, I have an internal ASP.NET application that I'm are using to send e-mails out based on a single milepost or milepost range entered. I'm trying to do two things when a user clicks on the submit button to submit a form that contains one or two Mileposts: 1) If a Milepost range larger than 5 miles is entered, I would like to pop up a confirmation box to confirm the range.
3
6490
by: Michael_R_Banks | last post by:
I'm trying to dynamically build a table that allows users to remove rows when they click a corresponding button. For some reason, whenever I add the button to the table, it never fires the onclick event. I'm stumped with this one, any assistance would be appreciated. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:// www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"...
0
8816
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
8717
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
8498
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
8600
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6162
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
4150
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
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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
1930
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.