Source Code for the showBook() Example : Objects Object Oriented : Language Basics : JavaScript DHTML examples (example source code) Organized by topic

JavaScript DHTML
C++
PHP
JavaScript DHTML Home »  Language Basics   » [  Objects Object Oriented  ]   
 



Source Code for the showBook() Example

Please note that some example is only working under IE or Firefox.


/*
JavaScript Unleashed, Third Edition
by Richard Wagner and R. Allen Wyke 

ISBN: 067231763X
Publisher Sams CopyRight 2000

*/

<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() {    objWindow = window.open("""""width=600,height=300");
    objWindow.document.write("<html><body >");
    objWindow.document.write("<h1>Object Description</h1>");
    objWindow.document.write("<p>");
    objWindow.document.write("Book Title: " this.title + "<br>");
    objWindow.document.write("Author: " this.author + "<br>");
    objWindow.document.write("ISBN: " this.ISBN + "<br>");
    objWindow.document.write("Subject: " this.subject + "<br>");
    objWindow.document.write("Allen's Rating: " this.rating + "<br>");
    objWindow.document.write("</body ></html>");
    objWindow.document.close();
  }
   
  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("Cost of Discipleship""Dietrich Bonhoeffer","1-57521-118-1""Grace"5);
  fkBook = new book("The Once and Future King""T.H. White","1-57521-112-1""Camelot"5);
  olBook = new book("On Liberty""John Stuart Mill","1-53221-118-1""Political Philosophy"4);
  iaBook = new book("Icarus Agenda""Robert Ludlum","1-53221-118-1""Political Thriller"3);
  cnBook = new book("Chronicles of Narnia""C.S. Lewis","1-53231-128-1""Children's Fiction"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">Cost of Discipleship</option>
        <option value="fkBook">The Once and Future King</option>
        <option value="olBook">On Liberty</option>
        <option value="iaBook">Icarus Agenda</option>
        <option value="cnBook">Chronicles of Narnia</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
1.  Object utility: create, parse and profile
2.  Define Object, use its instance
3.  Define and use object
4.   Creating an Object and Using Object Instance Properties and Methods
5.   Object-Oriented Planetary Data Presentation
6.  The Book Object Definition
7.  Complete Example of Using the employee, client, and project Objects
8.  Using the Book Object Constructor
9.  Creating Objects Dynamically
10.  Object to array
11.  Utility class for JavaScript class definitionHas Download File
























Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.