Click to See Complete Forum and Search --> : Hi It's Finaritwo With My Code


finaritwo
04-21-2006, 09:46 PM
just to let you know, i'm not in school, soo it's not homework, but i'm trying to learn javascript. i've come this far with my code, where i'm trying to create a custom object with four properties; firstname,lastname,DOB,salary,and a method called display,to display all four properties. then i need to create an instance of this object and prompt for each one of the four properties and then invoke the display method to display all properties in an HTML table like: firstname lastname DOB salary firstname entered lastname entered DOB entered salary entered can somebody please help me by looking at my code and to tell me where i'm going wrong. thanks.... <Html>
<Head>
<body>
<script type="Text/java script".
var First Name
var Last Name
var DOB
var Salary
function get_info()
{
First name=prompt("Enter the first name:","")
Last Name=prompt("Enter the last name:","")
DOB=prompt("Enter the data of birth:","")
Salary=prompt("Enter the salary:","")
disp_info()
}
function disp_info()
{
document.write("the first name is:" + First name +"<br>")
document.write("the last name is:" + Last Name +"<br>")
document .write("the salary is:" + Salary +"<br>")
document.write("the data of birth is:" + DOB +"<br>")

}

</script>
</Head>
<body>
<form>
<input type="button" onClick="get_info()" value="Get personal info">
</Form>
</body>
</Html>

Orc Scorcher
04-22-2006, 03:17 AM
(...)
<script type="Text/java script".JavaScript's mime type is text/javascript, not Text/java script. Your script tag doesn't end with >
var First Name
var Last Name
Variable names must not contain spaces. Use FirstName or First_Name.
First name=prompt("Enter the first name:","")Case is important: FirstName and Firstname are two different variables.

felgall
04-22-2006, 03:55 AM
Nothing in your code is creating your custom object.

finaritwo
04-22-2006, 08:28 PM
thanks for your interest, i'm still not understanding the reference to the custom object? learning on my own is not as easy as i thought, it's been difficult putting together simple tasks, but i need to view it more to understand it from the text.. thanks

felgall
04-22-2006, 08:40 PM
You create a custom object using a function by that name and then attach properties and methods to it. There are several different ways to attach methods but properties are usually created using this.propertyname. For example:

function myCustomObject() {
this.propertyOne = 'something';
this.propertyTwo = 9;
}

var myObj = myCustomObject();
alert(myObj.propertyOne);