Doubt in basic javascript call

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ss0007
    New Member
    • Mar 2008
    • 2

    Doubt in basic javascript call

    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,Firefo x. 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 ?

    Code:
    <html>
    <head><title>Test page</title>
    </head>
    <body>
    <form name="form1">
    <INPUT TYPE="button" NAME="myButton" VALUE="Press This" onClick="click()">
    </form>
    <script>
    function click(){
    	alert('Hi');
    }
    </script>
    </body>
    </html>
  • vee10
    New Member
    • Oct 2006
    • 141

    #2
    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

    Code:
    <html>
    <head><title>Test page</title>
    </head>
    <body>
    <form name="form1">
    <INPUT TYPE="button" NAME="myButton" VALUE="Press This" onClick="click1()">
    </form>
    <script>
    function click1(){
    	alert('Hi');
    }
    </script>
    </body>
    </html>


    Originally posted by ss0007
    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,Firefo x. 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 ?

    Code:
    <html>
    <head><title>Test page</title>
    </head>
    <body>
    <form name="form1">
    <INPUT TYPE="button" NAME="myButton" VALUE="Press This" onClick="click()">
    </form>
    <script>
    function click(){
    	alert('Hi');
    }
    </script>
    </body>
    </html>

    Comment

    • ss0007
      New Member
      • Mar 2008
      • 2

      #3
      Hi vee10 , thx for your reply ....
      I just thought for a moment that it could be bug in js ...

      Comment

      Working...