473,516 Members | 2,889 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Doubt in basic javascript call

2 New Member
Hi everyone ,

I was testing the following piece of code and unable to proceed because
the click() method is not invoked for the button's onclick event.
The same function works fine in the onload of the body tag. Moreover the code doesnt work in IE,Opera,Firefox. There are only four lines and simple HTML statements but I am unable to find a reason.Can someone
spot me the error that I have done here ?

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head><title>Test page</title>
  3. </head>
  4. <body>
  5. <form name="form1">
  6. <INPUT TYPE="button" NAME="myButton" VALUE="Press This" onClick="click()">
  7. </form>
  8. <script>
  9. function click(){
  10.     alert('Hi');
  11. }
  12. </script>
  13. </body>
  14. </html>
  15.  
Mar 31 '08 #1
2 1052
vee10
141 New Member
Hi,

Change the function name u should use the event name as the function name ie in ur case onclick event should not have the function name as click() and same rule applies for other events also

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head><title>Test page</title>
  3. </head>
  4. <body>
  5. <form name="form1">
  6. <INPUT TYPE="button" NAME="myButton" VALUE="Press This" onClick="click1()">
  7. </form>
  8. <script>
  9. function click1(){
  10.     alert('Hi');
  11. }
  12. </script>
  13. </body>
  14. </html>
  15.  


Hi everyone ,

I was testing the following piece of code and unable to proceed because
the click() method is not invoked for the button's onclick event.
The same function works fine in the onload of the body tag. Moreover the code doesnt work in IE,Opera,Firefox. There are only four lines and simple HTML statements but I am unable to find a reason.Can someone
spot me the error that I have done here ?

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head><title>Test page</title>
  3. </head>
  4. <body>
  5. <form name="form1">
  6. <INPUT TYPE="button" NAME="myButton" VALUE="Press This" onClick="click()">
  7. </form>
  8. <script>
  9. function click(){
  10.     alert('Hi');
  11. }
  12. </script>
  13. </body>
  14. </html>
  15.  
Mar 31 '08 #2
ss0007
2 New Member
Hi vee10 , thx for your reply ....
I just thought for a moment that it could be bug in js ...
Apr 1 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1385
by: mahesh | last post by:
Hi all, I have a doubt with OOAD and Dialogs. I have a Dialog Class. tkSimple.py It contains a class body as below. Now I am calling the tkSimple.py in another python program and using the default body, and everything from tkSimple.py. Now my requirement is as follows I need to popup a couple of other dialog boxes with a little...
7
9263
by: Michael Foord | last post by:
#!/usr/bin/python -u # 15-09-04 # v1.0.0 # auth_example.py # A simple script manually demonstrating basic authentication. # Copyright Michael Foord # Free to use, modify and relicense. # No warranty express or implied for the accuracy, fitness to purpose
7
1631
by: JCO | last post by:
I have several JavaScripts in a web page. Each script is in an individual file with extension .js. I want to know if it is possible to put all functions in one single page. If so, how do I call the specific script that I want to run. This is how I call an individual script: <SCRIPT LANGUAGE="JavaScript" src="valForm.js"></SCRIPT> Where...
2
1467
by: Eli | last post by:
Hi gurus, My question is about exchanging data on a basic HTML page between a JavaScript piece of code and a Java client-side <APPLET> residing on the same webpage. To demonstrate the idea of data encription at the client side to students my idea is to build a simple <FORM> on the webpage with 2 text fields and a submit button. The...
17
2379
by: blueapricot416 | last post by:
This is a very basic question -- but I can't find the answer after looking for 20 minutes. If you code something like: function set_It() { setTimeout('Request_Complete("apple", -72)',5000) } and call it 50 times, will it cause problems because you are not
28
1890
by: dutche | last post by:
Hi, there is some kind of difference in these two statements? float num = 154.87; printf("There is : $0.0f",num); and float num = 154.87;
43
2344
by: Bill H | last post by:
25 years ago every computer came with some form of Basic interpreter so you could use yoru computer without having to buy more software. Is Javascript (teamed with HTML) set to become the new Basic, where anyone with a computer can start writing code without having to purchase any expensive languages? Bill H
7
1714
by: MikeB | last post by:
Hello All, I am new to ajax and wanted to start by trying something simple. I have a web form with an updatepanel and then inside the update panel I have a listbox. Then outside of the updatepanel I have a button. In my buttons click event in the cs / code behind, I have a loop that just inserts items in the listbox. My question is, once I...
3
2367
by: pavanpvss | last post by:
hi , I have written a javascript function like this. function call(frm) { var loc_name = document.frm.loca.value; //alert('<'+loc_name+'>'); //var objRegExp = /^(\s*)(\b*)/; //if(objRegExp.test(loc_name)) { //alert("got it");
6
1135
by: sheldonlg | last post by:
Simple overview: I want to call a function in a javascript duntion where the name of the called function is an argument value passed into the javascript function. Here is what I want: On the html pages: page1: onclick="A('a', 'C')" In the library:
0
7182
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...
0
7408
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. ...
0
7581
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...
0
7548
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...
1
5110
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...
0
3267
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...
0
3259
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1624
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
0
488
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...

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.