Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (13.1k points)

Can anyone help me with my code, I want to call function1() and as well as function0(), but it is only calling function1(). How can I make my code to call both the functions? 

<!DOCTYPE html>

  <html>

  <head>

  <script>

   document.getElementById("Save").onclick = function function0()

    {

     alert("Intellipaat");

     //validation code to see State field is mandatory.  

    }   

    function function1()

    {

       alert("function1 called");

       //form validation that recalls the page showing with supplied inputs.    

    }

  </script>

  </head>

  <body>

  <form name="form1" id="form1" method="post">

            State: 

            <select id="state ID">

               <option></option>

               <option value="ap">ap</option>

               <option value="bp">bp</option>

            </select>

   </form>

   <table><tr><td id="Save" onclick="f1()">click</td></tr></table>

   </body>

   </html>

Can anyone help me with this?

1 Answer

0 votes
by (26.7k points)

Basically, you are trying to attach an event listener earlier, than the element. You can try the below code which will help you to run the code:

function function1() {

    alert("function1 called");

    //form validation that recalls the page showing with supplied inputs.    

}

window.onload = function() {

    document.getElementById("Save").onclick = function function0() {

        alert("hello");

        function1();

        //validation code to see State field is mandatory.  

    }

}

I hope this will help.

Want to become a Java Expert? join Java Certification now!!

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Mar 4, 2021 in Java by dante07 (13.1k points)
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...