Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
| Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 4th, 2004, 11:29 AM
Authorized User
 
Join Date: Nov 2003
Location: Redcar, Cleveland, United Kingdom.
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default calling functions with conditions

Hi

Is it possible to call different functions for different conditions.
I have 3 different functions that do calculations.
I want to write if this condition call this function else if this condition call function 2 and so on.
I have tried it using if statements but I keep getting errors, could someone please point me in the right direction.

Thanks in advance

 
Old February 4th, 2004, 02:51 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

if(<condition 1>){
    function1();
} elseif(<condition 2>){
    function2();
} elseif(<condition 3>){
    function3();
}


If the condition is just a test of multiple possible values of a variable use a switch:

switch(variable){
    case 1:
        function1();
        break;
    case 2:
        function2();
        break;
    case 3:
        function3();
        break;
}

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old February 5th, 2004, 09:29 AM
Authorized User
 
Join Date: Nov 2003
Location: Redcar, Cleveland, United Kingdom.
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for that,Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
Help calling and using a functions in visual c++ 6 method Visual C++ 0 July 8th, 2006 05:20 PM
Calling PHP functions from ASP Smoobly Classic ASP Basics 4 January 10th, 2005 06:11 PM
Calling functions ejmichaud Access VBA 2 July 16th, 2004 10:03 AM
Calling functions in Windows? jacob C# 0 November 5th, 2003 03:57 PM
Calling subs & Functions Zooker Beginning VB 6 4 August 20th, 2003 07:09 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.