Calling Multiple function in javascript

Is it possible to call two or multiple functions in javascript ????

Let's see on this blog,

First Method

The most common way to call multiple functions through on-click in  HTML  such as

<input type="text" name="" value="" onclick="fun1();fun2()">

In on-click it should be separated by ;

By using this we can call n number of function in javascript.Let's see an example code.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
    <h1 id="eg"></h1>
   
    <button type="button" name="button" onclick="function1();function2()">Click me</button>
    <script type="text/javascript">
      function function1()
      {
        alert("hi");
      }
      function function2()
      {
        document.getElementById('eg').innerHTML = "Working";
      }
    </script>
  </body>
</html>



Second Method

In this method, we will call a function through on-click and that function will call other function inside it.
Let see an example code:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
    <h1 id="eg"></h1>

    <button type="button" name="button" onclick="fun()">Click me</button>
    <script type="text/javascript">
      function fun()
      {
        function1();
        function2();
      }
      function function1()
      {
      alert("hi");
      }
      function function2()
      {
        document.getElementById('eg').innerHTML = "Working";
      }
    </script>
  </body>
</html>


I hope this two method will be helpfull to you.If you know any other method kindy share in the comment box.Dont forget to like and share this blog.




Comments

Popular posts from this blog

Artificial Intelligence

The taxonomy of CASE Tools

Zoho Second round - adding a digit to all the digits of a number