Source Code for the showBook() Example
<html>
<head>
<title>Using the book object</title>
<script type="text/javascript">
<!--
function book(title, author, ISBN, subject, rating) {
this.title = title;
this.author = author;
this.ISBN = ISBN;
this.subject = subject;
this.rating = rating;
this.show = show;
}
function show() {
alert(this.title + " "+ this.author + " " + this.ISBN + " " + this.subject + " " + this.rating);
}
function assignRating() {
selectedBook = document.form1.bookList.options[document.form1.bookList.selectedIndex].value;
selectedBook = eval(selectedBook);
selectedBook.rating = document.form1.rating.options[document.form1.rating.selectedIndex].text;
}
function showBook() {
selectedBook = document.form1.bookList.options[document.form1.bookList.selectedIndex].value;
selectedBook = eval(selectedBook);
selectedBook.show();
}
// Execute on loading
dbBook = new book("A", "AA","1-11111-118-1", "A1", 5);
fkBook = new book("B", "BB","1-22222-112-1", "B1", 5);
olBook = new book("C", "CC","1-33333-118-1", "C1", 4);
iaBook = new book("D", "DD","1-44444-118-1", "D1", 3);
cnBook = new book("E", "EE","1-55555-128-1", "F1", 5);
//-->
</script>
</head><body>
<h1>Book Objects</h1>
<form name="form1">
<p>
Select a book:
</p>
<p>
<select name="bookList" size=1>
<option value="dbBook">A</option>
<option value="fkBook">B</option>
<option value="olBook">C</option>
<option value="iaBook">D</option>
<option value="cnBook">E</option>
</select>
</p>
<p>
Assign a rating:
</p>
<p>
<select name="rating" size=1>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</p>
<p>
Click to assign:
</p>
<p>
<input type="button" name="Assign" value="Assign" onClick="assignRating()">
</p>
<p>
Click to show:
</p>
<p>
<input type="button" name="Show" value="Show" onClick="showBook()">
</p>
</form></body>
</html>
Related examples in the same category