Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem w/ Functions

Status
Not open for further replies.

BigCatMCS

Programmer
Apr 29, 2004
57
US
Can someone help me on the following script? I keep on getting that number is not defined. thanks.


<HTML>
<HEAD><TITLE>Testing</TITLE>

<SCRIPT LANGUAGE="JavaScript">

function human(name,title) {
if (EmpName == "Mark") {
document.writeln("<br>" + empName + " is an employee of XYZ" + "<br>")
}
else {
document.writeln("That is all the name(s) that we have today.")
}
}

function employee(Name,Number,Title) {

this.empName=name
this.empNumber=number
this.empTitle=title
this.titleReview=human(name,title)
}

</SCRIPT>
</HEAD>
<BODY>
<BR>
<SCRIPT LANGUAGE=JavaScript>

mark = new employee("Mark C. Davis", "10309", "Supervisor")
mark.titleReview

</SCRIPT>
</BODY>
</HTML>
 
Not sure exactly what you're trying to do, but you misnamed variables as well as did some other things that would cause this script to fail.

Here is what I determined is a "fixed" version:

Code:
<HTML>
<HEAD><TITLE>Testing</TITLE>

<SCRIPT LANGUAGE="JavaScript">

function human(name,title)  {
    if (name == "Mark C. Davis")   {
        document.writeln("<br>" + name + " is an employee of XYZ" + "<br>")
    }
    else  {
        document.writeln("That is all the name(s) that we have today.")
    }
}

function employee(Name,Number,Title)  {
    this.empName = Name
    this.empNumber = Number
    this.empTitle = Title
    this.titleReview = human(Name,Title)
}

</SCRIPT>
</HEAD>
<BODY>
<BR>
<SCRIPT LANGUAGE=JavaScript>

mark = new employee("Mark C. Davis", "10309", "Supervisor")
mark.titleReview

</SCRIPT>
</BODY>
</HTML>

*cLFlaVA
----------------------------
When will I be able to see what other members can see about myself? It's been like, a freakin' month already!
 

I'm still getting an error on "name not defined". I readjusted my script (yeah, they were dumb mistakes) - but it's still not working. Any more ideas? Thx.
 
Javascript is case sensitive - "name" and "Name" aren't the same.

Also, Number is built-in Javascript class name. Maybe this doesn't matter, but still try to use more unique names.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top