calling two js functions using one submit button

Discussion in 'Web Design, HTML And CSS' started by rekha, Mar 19, 2008.

  1. rekha

    rekha New Member

    Joined:
    Jan 17, 2008
    Messages:
    83
    Likes Received:
    0
    Trophy Points:
    0
    Hi

    I want to call two js functions using one submit button.I have tried the below code.But it gives error.

    Code:
    <script language=javascript>
    function one()
    {
    document.write("hai");
    }
    function two()
    {
    document.write("All");
    }
    </script>
    <form>
    <input type=button value="ok" onClick="two();one()" > 
    </form>
    I got the error as

    Code:
    one is not defined.
    But i am getting All as output.

    Pls anybody solve this ....

    Regards
    Rekha
     
  2. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    Try this
    HTML:
    <script language=javascript>
    function one()
    {
    document.write("hai");
    }
    function two()
    {
    document.write("All");
    }
    
    function a()
    {
    	two();
    	one();
    }	
    </script>
    <form>
    <input type=button value="ok" onClick="a();" > 
    </form>
    
     
  3. rekha

    rekha New Member

    Joined:
    Jan 17, 2008
    Messages:
    83
    Likes Received:
    0
    Trophy Points:
    0
    Hi Pradeep,

    I want to call the function as i have in the above example that i have given.What is the error in it?


    Regards
    Rekha
     
  4. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    HTML:
    <script language=javascript>
    function one()
    {
    alert("hai");
    }
    function two()
    {
    alert("All");
    }
    </script>
    <form>
    <input type=button value="ok" onClick="two();one()" > 
    </form>
    
    But your version doesn't work because you are using document.write, after calling the first function the document is overwritte, so, it can't find function one().
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice