Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Mootools create new element onclick function params

Posted on 2012-09-05
2
Medium Priority
?
476 Views
Last Modified: 2012-09-10
Trying to add a function to an anchor using mootools. Need help setting the parameters of the function call. The creation of the links is in a loop changing the id and names of each and attempting to set new parameters for the function being set in the onclick event. I'm having trouble figuring out how to set the params based on variables. Seems I need to set the function up in a string possibly and eval it or something...

Simple example of the element creation... assume a loop and that var1,2,3 are changing.

var myAnchor = new Element('a', {
    href: 'http://mootools.net',
    'class': 'myClass',
    html: 'Click me!',
    styles: {
        display: 'block',
        border: '1px solid black'
    },
    events: {
        click: function(){
            someFunction(var1, var2, var3); // <- HERE
        }
        }
    }
});

Open in new window



Any help greatly appreciated!
Thanks,
Dan
0
Comment
Question by:kindaprog
  • 2
2 Comments
 
LVL 25

Expert Comment

by:Kyle Hamilton
ID: 38371779
What are you trying to pass to the function (variables)?

What is the function being called onclick?
0
 
LVL 25

Accepted Solution

by:
Kyle Hamilton earned 2000 total points
ID: 38372004
something like this?

var myAnchor = new Element('a', {
                href: 'http://mootools.net',
                'class': 'myClass',
                html: 'Click me!',
                styles: {
                    display: 'block',
                    border: '1px solid black'
                },
                events: {
                    click: function(){
                        doAlert(this); // <- HERE
                        return false; // disable the link for this example
                    }
                    }
                }).inject(document.getElementsByTagName("body")[0]);
                
                function doAlert(var1){
                    alert(var1);
                }

Open in new window

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question