forked from Varanasi-Software-Junction/JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJava Script Objects.html
More file actions
122 lines (101 loc) · 2.17 KB
/
Java Script Objects.html
File metadata and controls
122 lines (101 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
Object
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Java Script Objects</title>
<script>
var book= {
name: "Basic C",
subject: "C",
price: 50
//discountedprice:function(){return this.price-10;};
};
function f()
{
document.getElementById("txtBookName").value=book.name;
document.getElementById("txtSubject").value=book['subject'];
document.getElementById("txtPrice").value=book.price;
// alert(book.discountedprice());
}
function f1()
{
book.name= document.getElementById("txtBookName").value;
book['subject']= document.getElementById("txtSubject").value;
book.price= document.getElementById("txtPrice").value;
}
</script>
</head>
<body>
Book Name<input type="text" id="txtBookName"/>
<br/>
Subject<input type="text" id="txtSubject"/>
<br/>
Price<input type="text" id="txtPrice"/>
<br/>
<input type="button" onclick="f()" value="Find"/>
<input type="button" onclick="f1()" value="Set"/>
</body>
</html>
Object with function
<!DOCTYPE html>
<html>
<body>
<p id="data"></p>
<script>
var book = {
name: "Basic C",
subject : "C",
price : 500,
discountedPrice : function() { return this.price-10;}
};
document.getElementById("data").innerHTML =book.discountedPrice();
</script>
</body>
</html>
Object Array
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Java Script Objects</title>
</head>
<body>
Book Name<input type="text" id="txtBookName"/>
<br/>
Subject<input type="text" id="txtSubject"/>
<br/>
Price<input type="text" id="txtPrice"/>
<br/>
Discounted Price<input type="text" id="txtDiscountedPrice"/>
<br/>
<input type="button" onclick="next()" value=">>"/>
</body>
<script>
var book= [{
name: "Basic C",
subject: "C",
price: 50,
discount: 10,
discountedPrice : function() { return (100.0-this.discount)* this.price/100;}
},
{name: "Basic C++",
subject: "C++",
price: 70,
discountedPrice : function() { return this.price-10;}
}
];
var i=0;
var n=book.length;
function next()
{
document.getElementById("txtBookName").value=book[i].name;
document.getElementById("txtSubject").value=book[i]['subject'];
document.getElementById("txtPrice").value=book[i].price;
document.getElementById("txtDiscountedPrice").value=book[i].discountedPrice();
if(i<n-1)
i++;
}
next();
</script>
</html>