Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-17-2013, 10:43 AM   PM User | #1
hafizrashid
New to the CF scene

 
Join Date: Jan 2013
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
hafizrashid is an unknown quantity at this point
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>
hafizrashid is offline   Reply With Quote
Old 01-17-2013, 11:15 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
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.
devnull69 is offline   Reply With Quote
Old 01-17-2013, 11:28 AM   PM User | #3
hafizrashid
New to the CF scene

 
Join Date: Jan 2013
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
hafizrashid is an unknown quantity at this point
sir.im javascript newbie

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

please sir
hafizrashid is offline   Reply With Quote
Old 01-17-2013, 11:33 AM   PM User | #4
hafizrashid
New to the CF scene

 
Join Date: Jan 2013
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
hafizrashid is an unknown quantity at this point
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”
hafizrashid is offline   Reply With Quote
Old 01-17-2013, 12:50 PM   PM User | #5
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,037
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
__________________

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.

Last edited by Philip M; 01-17-2013 at 12:54 PM..
Philip M is offline   Reply With Quote
Old 01-17-2013, 02:55 PM   PM User | #6
hafizrashid
New to the CF scene

 
Join Date: Jan 2013
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
hafizrashid is an unknown quantity at this point
sorry all
hafizrashid is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:27 PM.


Advertisement
Log in to turn off these ads.