
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How do I run two or more functions when using 'onclick' JavaScript?
Let’s first set a button −
<button type="submit" onclick="callTwoOtherFunctions()"> Call </button>
Above, we have set a function under “onclick” to call two other functions −
function callTwoOtherFunctions(){ fun1(); fun2(); }
In this way, work around the fun1() and fun2() as in the complete code below −
Example
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initialscale=1.0"> <title>Document</title> <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> </head> <body> <button type="submit" onclick="callTwoOtherFunctions()"> Call </button> <script> function callTwoOtherFunctions(){ fun1(); fun2(); } function fun1(){ console.log("Function1()") } function fun2(){ console.log("Function2()") } </script> </body> </html>
To run the above program, save the file name “anyName.html(index.html)” and right click on the file. Select the option “Open with Live Server” in VS Code editor.
Output
This will produce the following output −
When you click on the Call button, you will get the following output. The snapshot is as follows −
- Related Articles
- How do I run two python loops concurrently?
- What is onclick not working for two or more links for same function in JavaScript?
- How to call multiple JavaScript functions in onclick event?
- How to run a function after two async functions complete - JavaScript
- How to run functions iteratively with async await in JavaScript?
- How do I run a Python program under Windows?
- How do I add two numbers without using ++ or + or any other arithmetic operator in C/C++?
- How do I add a simple onClick event handler to an HTML5 canvas element?
- Can Python functions run in html as javascript does?
- How to calculate GCD of two or more numbers/arrays in JavaScript?
- How do I enumerate functions of a Python class?
- In MySQL, how can I combine two or more strings along with a separator?
- How to find the common elements between two or more arrays in JavaScript?
- How to use spread operator to join two or more arrays in JavaScript?
- When to use anonymous JavaScript functions?

Advertisements