Onclick not call two functions why

Discussion in 'JavaScript' started by macaela, Jul 14, 2011.

  1. #1
    Hi i've researched evrywhere on how to call to function and i keep seeing that all i need is the following line but is not working well at least when i try on to run on w3school text editor http://www.w3schools.com/js/tryit.asp?filename=tryjs_function1
    onClick="doFunction1(); doFunction2(); "
    Code (markup):
    this is how my whole code looks like why it only call the first function why??

    <script type="text/javascript">
    function doFunction1()
    {
    document.write("Hello World!");
    }
    
    function doFunction2()
    {
    document.write("morning");
    }
    </script>
    </head>
    
    <body>
    <form>
    <input type="button" value="Click me!" onClick="doFunction1(); doFunction2(); " />
    </form>
    Code (markup):

     
    macaela, Jul 14, 2011 IP
  2. spletnisistemi

    spletnisistemi Peon

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    onClick="doFunction3();"


    <script type="text/javascript">
    function doFunction1()
    {
    document.write("Hello World!");
    }

    function doFunction2()
    {
    document.write("morning");
    }

    function doFunction3()
    {
    doFunction1();
    doFunction2();
    }
    </script>
     
    spletnisistemi, Jul 15, 2011 IP
  3. - MinimalBook -

    - MinimalBook - Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Works for me and everyone else except you.
     
    - MinimalBook -, Jul 15, 2011 IP
  4. macaela

    macaela Active Member

    Messages:
    181
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #4
    this way working for you???

    <script type="text/javascript">
    function doFunction1()
    {
    document.write("Hello World!");
    }
    
    function doFunction2()
    {
    document.write("morning");
    }
    </script>
    </head>
    
    <body>
    <form>
    <input type="button" value="Click me!" onClick="doFunction1(); doFunction2(); " />
    </form>
    Code (markup):
     
    macaela, Jul 16, 2011 IP
  5. BRUm

    BRUm Well-Known Member

    Messages:
    3,086
    Likes Received:
    61
    Best Answers:
    1
    Trophy Points:
    100
    #5
    Which browser are you using? Have you made sure you haven't disabled Javascript?
     
    BRUm, Jul 16, 2011 IP
  6. macaela

    macaela Active Member

    Messages:
    181
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #6
    macaela, Jul 16, 2011 IP
  7. macaela

    macaela Active Member

    Messages:
    181
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #7
    well it only runs the first function which write hello world but doesnt run the second function whic is meant to write morning
     
    macaela, Jul 16, 2011 IP
  8. BRUm

    BRUm Well-Known Member

    Messages:
    3,086
    Likes Received:
    61
    Best Answers:
    1
    Trophy Points:
    100
    #8
    This works fine for me:

    
    <html>
    <head>
    <script type="text/javascript">
    function displaymessage1()
    {
    alert("Hello World!");
    }
    
    function displaymessage2()
    {
    alert("Hello again");
    }
    </script>
    </head>
    
    <body>
    <form>
    <input type="button" value="Click me!" onclick="displaymessage1(); displaymessage2();" />
    </form>
    
    <p>By pressing the button above, a function will be called. The function will alert a message.</p>
    
    </body>
    </html>
    
    Code (markup):
    If this doesn't for you tell us which browser you use, which version and whether you're sure you have JS enabled.
     
    BRUm, Jul 16, 2011 IP
  9. macaela

    macaela Active Member

    Messages:
    181
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #9
    thansk yeah it is working now just one more thing if you can that i am trying to work

    i have this functions which load the video file onto the player
    <a title="Testimonial One" href="#" onClick="loadNplay({file="videos/film.mp4" hd.file="videos/film.mp4"});"><img src="images/24hrs.jpg" border="0" title="picture" /></a>
    Code (markup):
    can i also include the second function the same one as the one you gave me by adding the second funcion name after this function [displaymessage2();] so it would be like this?
    <a title="Testimonial One" href="#" onClick="loadNplay({file="videos/film.mp4" hd.file="videos/film.mp4"}); displaymessage2();" /><img src="images/24hrs.jpg" border="0" title="picture" /></a>
    Code (markup):
    do you think that will work?
     
    macaela, Jul 16, 2011 IP