What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 2003 |  Welcome, Guest!   Register  Login
 Home > Code Snippets > JavaScript > Explain with a code sample how to pass a method in javascript as an argument to another javascript method? ...
Tripati_tutu

Explain with a code sample how to pass a method in javascript as an argument to another javascript method?

 Code Snippet posted by: Tripati_tutu | Posted on: 12/8/2010 | Category: JavaScript Codes | Views: 1342 | Status: [Member] | Points: 40 | Alert Moderator   


<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title></title>
<script type="text/javascript">
function Sample(a)
{
var message;
if (a == 1)
{
message = "First function is executed";
ExecuteFunction(Function1, message)
}
if (a == 2)
{
message = "Second function is executed";
ExecuteFunction(Function2, message)
}
}

//Executes the Function that is passed as parameter
function ExecuteFunction(funObj, params)
{
funObj(params);
}
function Function1(message)
{
alert("Function1: " + message);
}
function Function2(message)
{
alert("Function2: " + message);
}
</script>
</head>
<body>
<input type = "button" onclick = "Sample(1)" value = "For Fun1" />
<input type = "button" onclick = "Sample(2)" value = "For Fun2" />
</body>
</html>


Here I have created two buttons. So accordingly when you will click on the buttons, the corresponding function will automatically execute.
Found interesting? Add this to:


 Responses

Kishork80
Posted by: Kishork80 | Posted on: 12/8/2010 | Level: Starter | Status: [Member] | Points: 10 | Alert Moderator 

intresting :)

kishor kumar

>> Write Response - Respond to this post and get points

More codes snippets

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/23/2013 4:01:07 PM