Javascript: How to call the same function 2 times in the same mouse action event?
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Javascript: How to call the same function 2 times in the same mouse action event?

  1. #1

    resolved

    How can I call the same function 2 times in the same mouse action event?

    <input type="submit" onMouseOver="myfunction(arg1,arg2)">

    Here I wanna call the same javascript function 2 times.

    I tried onMouseOver="myfunction(arg1,arg2)","myfunction(ar g3,arg4)" but it didnt seem to work.

    Could I use onMouseOver="myfunction(arg1,arg2)" onMouseOver="myfunction(arg3,arg4)" ?

    I hope someone know how to do this, otherwise I must make the function twice as big to do the operations I want.


  2. #2
    Moderator
    Join Date
    Aug 2000
    Posts
    1,455
    Hiya!

    You have one of two options. Either create a new function which will accept all four arguments, then call your function twice with each set like so:

    Code:
    function myFunction(first, second)
    {
      ...whatever...
    }
    
    function myCaller(arg1, arg2, arg3, arg4)
    {
        myFunction(arg1, arg2);
        myFunction(arg2, arg4);
    }
    
    ...then on your link...
    
    <input type="submit" onMouseOver="myCaller(arg1,arg2,arg3,arg4)">

    ... or use a semi-colon in the onMouseOver handler to call the function twice:

    Code:
    <input type="submit" onMouseOver="myFunction(arg1,arg2); myFunction(arg3,arg4);">
    I have tested this with the following code and it works a treat:

    Code:
    <html>
    <a href="" onMouseOver="alert('one'); alert('two');">hahaha</a>
    </html>
    I hope this helps!

    Regards,

    Steve

  3. #3
    Yepp, the semi-colon made it work.

    Thanks again NETbreed

  4. #4
    Registered User
    Join Date
    Feb 2015
    Posts
    1

    Lightbulb Onclick multiple choices at same time

    Hi I have a similar problem, I have a javascript which can open popup and then passing values onclick.

    But my requirement is adding multiple values, current script only add 1 per onclick and if I click another, it deletes previous one and add new 1, how can I add multiple values 1234

    Please check following javascript which i uploaded live demo on http://goo.gl/WDNrAZ:



    index.html

    Code:
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Untitled Document</title>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    function showList() {
      sList = window.open("popup.html", "list", "width=150,height=210");
    }
    function remLink() {
      if (window.sList && window.sList.open && !window.sList.closed)
        window.sList.opener = null;
    }
    // -->
    </SCRIPT>
    </head>
    
    <body>
    <FORM NAME="stockForm">Enter your favorite tech stock:
    <INPUT TYPE="text" NAME="stockBox" SIZE="10" VALUE="">
    <INPUT TYPE="button" VALUE="list" onClick="showList()">
    </FORM>
    </body>
    </html>
    popup.html

    Code:
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Untitled Document</title>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    function showList() {
      sList = window.open("popup.html", "list", "width=150,height=210");
    }
    function remLink() {
      if (window.sList && window.sList.open && !window.sList.closed)
        window.sList.opener = null;
    }
    // -->
    </SCRIPT>
    </head>
    
    <body>
    <FORM NAME="stockForm">Enter your favorite tech stock:
    <INPUT TYPE="text" NAME="stockBox" SIZE="10" VALUE="">
    <INPUT TYPE="button" VALUE="list" onClick="showList()">
    </FORM>
    </body>
    </html>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center

Poll by Flashkit.com