Log In · Register

 
Solve this.
Maccabee
post Sep 1 2009, 05:41 PM
Post #1


Senior Member
*******

Group: Official Designer
Posts: 5,880
Joined: Nov 2007
Member No: 593,382



My teacher showed me, but I forgot and cant find what it is called or how to solve it.

CODE
function get_name(name)
{
    // test to make sure it is a string that isn't empty
    // test to make sure that it is at least 3 characters long
    // test to make sure that it is either Paul, John or Bob and no one else
    alert("Hi " + name);
}


How can I tell it what name is? and it would be mice if someone could tell me how to tell it the name too. Something like:

CODE
var name = prompt("What is your name?","");


This is javascript btw. Not php. I keep getting confused too...

I have watched all the lynda.com javascript tutorials and all the w3schools.com javascript tutorials and for some reason I cant solve this. Thanks.
 
 
Start new topic
Replies
Maccabee
post Sep 1 2009, 09:58 PM
Post #2


Senior Member
*******

Group: Official Designer
Posts: 5,880
Joined: Nov 2007
Member No: 593,382



O. I thought it did... haha.
CODE
<html>
<head>
<title>Script</title>
<script type="text/javascript" src="names.js"></script>
<script type="text/javascript">
function get_name()
</script>
</head>
<body>
Hello World!
</body>
</html>


Am i doing it right? They never taught me how to do this on w3schools or lynda.com. I need to look for practical javascript tutorials.
 
mipadi
post Sep 1 2009, 10:02 PM
Post #3


Senior Member
******

Group: Administrator
Posts: 2,648
Joined: Apr 2008
Member No: 639,265



QUOTE(jcp @ Sep 1 2009, 10:58 PM) *
Am i doing it right? They never taught me how to do this on w3schools or lynda.com. I need to look for practical javascript tutorials.

No:
  1. You're not calling the function with the correct parameters.
  2. You don't put "function" in front of the function call.

You probably want to do it on page load, like this:

CODE
<!-- header stuff -->
<body onload='get_name("Bob");'>
 

Posts in this topic


Closed TopicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members: