Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: onclick button

  1. #1
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    onclick button

    hi there,how to make my button click and shows every single string on every clicking...

    help me please

    <!DOCTYPE html>
    <html>
    <body>

    <p>Click the button to show the result.</p>

    <button onclick="myFunction('Car','Bus','Aeroplane')">Select a transport types</button>

    <p id="demo"></p>
    <p id="demo1"></p>
    <p id="demo2"></p>


    <script>
    function myFunction(carname,busname,planename)
    {
    var carname="Car";
    document.getElementById("demo").innerHTML=carname;
    {
    var busname="Bus";
    document.getElementById("demo1").innerHTML=busname;
    {
    var planename="Aeroplane";
    document.getElementById("demo2").innerHTML=planename;
    }
    }
    }

    </script>

    </body>
    </html>

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,396
    Thanks
    12
    Thanked 569 Times in 562 Posts
    Obviously you are doing basic homework ... and honestly you are not doing well

    You should learn about:
    - Meaning of the "var" keyword
    - Correct usage of {} brackets

    Hint: You don't need var ... the parameters have been automatically defined as arguments of the function. You don't need additional brackets inside the function as you don't need to have blocks there.

  • #3
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sir.im javascript newbie

    can u give me a example of coding to sattle my exercise...

    please sir

  • #4
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sir,how to make a code for this question?

    Question:
    Create a function that can take any number of parameters and returns a String that is a comma separated list.
    e.g. myFunction(“car”, “bus”, “airplane”); // returns “car, bus, airplane”

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,912
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    As a general rule, the people helping out in this forum don't write code for others (especially code that appears to be for homework), but try to help with fixing code that doesn't work. You may perhaps get someone to write this script for you, but you'll be far more likely to get help if you have made a substantial effort and written some code yourself. Then someone here will almost certainly help you correct/improve your work.

    e.g. myFunction(“car”, “bus”, “airplane”); // returns “car, bus, airplane”

    Note that you must use normal quotation marks " and not literary quotation marks “ ” . Do not use MS WORD or other word processor to write your code. Use only a text editor.
    Last edited by Philip M; 01-17-2013 at 12:54 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #6
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sorry all


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •