OnClick event

Discussion in 'Javascript' started by f1crazed@gmail.com, Feb 1, 2005.

  1. Guest

    Hello,

    I am wanting to fire the onClick event of button1 by pressing button2.
    Does anyone have a clue if this is even posible? If so PLEASE HELP!!
    Thanks.
    , Feb 1, 2005
    #1
    1. Advertising

  2. Lee Guest

    said:
    >
    >Hello,
    >
    >I am wanting to fire the onClick event of button1 by pressing button2.
    >Does anyone have a clue if this is even posible? If so PLEASE HELP!!
    >Thanks.
    >


    <button onclick="doSomething()">button1</button>
    <button onclick="doSomething()">button2</button>

    How is what you want different from this?
    Lee, Feb 1, 2005
    #2
    1. Advertising

  3. wrote:

    > I am wanting to fire the onClick event of button1 by pressing
    > button2. Does anyone have a clue if this is even posible?


    Here is a test document. Watch the differing behaviour of MSIE
    compared to other Browsers (Mozilla, Opera, Netscape 4) when
    clicking the second button:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN Transitional"
    "http://www.w3.org/TR/html4/transitional.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
    <title>Some Events</title>
    <script type="text/javascript">
    window.name = "myWindow";
    </script>
    </head>
    <body>
    <form action="" name="myForm"><p>
    <input type="button" value="1" name="myButton1"
    onclick="alert(this.name + '\n' + (event &amp;&amp; event.type))"
    >

    <input type="button" value="2" name="myButton2"
    onclick="var o = form.elements['myButton1'], h = o.onclick;
    if (typeof h == 'function') h()"
    >

    <input type="button" value="3" name="myButton3"
    onclick="var o = form.elements['myButton1'], h = o.onclick;
    if (h && h.apply) h.apply(o, [event])"
    >

    <input type="button" value="4" name="myButton4"
    onclick="var o = form.elements['myButton1'], h = o.onclick;
    if (h && h.apply) h.apply(this, [event])"
    >

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

    ciao, dhgm
    Dietmar Meier, Feb 1, 2005
    #3
  4. Guest

    Dietmar,
    Thankyou!!!! This is what I was wanting to do. Thanks so much!!!!

    JD
    , Feb 2, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hrvoje Vrbanc
    Replies:
    1
    Views:
    452
  2. JerryG
    Replies:
    0
    Views:
    413
    JerryG
    Dec 20, 2005
  3. bob
    Replies:
    3
    Views:
    175
  4. Replies:
    2
    Views:
    240
  5. Replies:
    4
    Views:
    165
Loading...

Share This Page