Results 1 to 3 of 3

Thread: Java script event and parameters

  1. #1
    Join Date
    Jun 2005
    Location
    Madrid
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Java script event and parameters

    Hi all!

    I am new forum user. My work is mainly in GIS programming (maps, routes, etc), more precisely i am developing a web map app.

    I am trying to keep separated js code form HTML and CSS, but i have some problems that i cannot resolve, for example, when i use:
    <a id="myID">Hello</a>

    then in a js file i put:

    var a = document.getElementById("myID");
    a.onmousedown = myFunction;

    myFunction() {
    alert(this.id);
    }

    But the problem is, what if I want to pass more parametes than event or this, i mean, what if the function is myFunction(param1,param2,param3). How can i handle this?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Code:
    <body>
    <a id="myID">Click</a>
    <script type="text/javascript">
    var a = document.getElementById("myID");
    a.onmousedown = function(){myFunction('&nbsp;Hello&nbsp;','green','yellow')};
    
    function myFunction(text, clr, bkgr) {
    a.innerHTML=text;
    a.style.color=clr;
    a.style.background=bkgr
    }
    
    </script>
    </body>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jun 2005
    Location
    Madrid
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thats exactly what I want! Thank you!

Bookmarks

Posting Permissions

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