Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 4th, 2006, 02:55 PM
Registered User
 
Join Date: Sep 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Advanced Help! Object Class Programming! I'm stuck

Hi all, I'm new to "advance" javascript and I need some help I dont mind if it's not written for me but a point in the right direction.

I've been using your book "Beginning JavaScript, 2nd Edition", and working through the ch 4 demo about object programming.

I'm building an app, that takes the contents of an Array (which will eventually be dynamic) and printing the array out via a specific formation.

I've written pretty much the shell of program, although I'll be re-writing the output to be done via DOM. ANYWAYS...

I've hit a brick wall due to two problems:
1) The first is how can I sort the array, as no matter where I put cinema.sort() in my app it crashes it. I want it sorted by localeGroup.
2) How can I dynamically put in a new <tr><td></td></tr> tag at the top and bottom of each new iteration of a localeGroup, BUT ONLY THE FIRST INSTANCE OF new localeGroup.

I.E. - Currently it outputs the array as it comes in nothing more, but I need to put in a <tr><td></td></tr> structure at the start of a new set of data. When it loops through the array when it sees a new localeGroup it'll put in a <tr><td></td></tr> and another <tr><td></td></tr> at the last element in that localeGroup.

current output:
[ malaga ][ £99 ][ Europe ]
[ orlando ][ £99 ][ USA ]
[ london ][ £99 ][ Europe ]

what i need:
[ NEW <tr><td></td></tr> ] <-- Element new localeGroup
[ malaga ][ £99 ][ Europe ]
[ london ][ £99 ][ Europe ]
[ NEW <tr><td></td></tr> ] <-- Element last localeGroup

[ NEW <tr><td></td></tr> ] <-- Element new localeGroup
[ orlando ][ £99 ][ USA ]
[ NEW <tr><td></td></tr> ] <-- Element last localeGroup

Cheers for any help you give me, hopefully I've explained myself correctly. I'm having trouble taking my Javascript skills to the next level. Hopefully someone will make my brain click :D

heres WORKING source for so far:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<body>
    <h2>Prices Array Printing/Sorting</h2>
        <script type="text/javascript">
            function dynamicPricing (localeName,localePrice, localeGroup) {
                this.localePrice = localePrice;
                this.localeName = localeName;
                this.localeGroup = localeGroup;
            }

            dynamicPricing.prototype.getLocalePrice = function() {
                return this.localePrice;
            }

            dynamicPricing.prototype.setLocalePrice = function(localePrice) {
                this.localePrice = localePrice;
            }

            dynamicPricing.prototype.getLocaleGroup = function() {
                return this.localeGroup;
            }

            dynamicPricing.prototype.setLocaleGroup = function(localeGroup) {
                this.film = localeGroup;
            }

            dynamicPricing.prototype.getLocaleName = function() {
                return this.localeName;
            }

            dynamicPricing.prototype.setLocaleName = function(localeName) {
                this.localeName = localeName;
            }

            function cinema()
            {
                this.bookings = new Array();
            }

            cinema.prototype.addLocale = function(localeName, localePrice, localeGroup)
            {
                this.bookings[localeName] = new dynamicPricing(localeName, localePrice, localeGroup);
            }

            cinema.prototype.getBookingsTable = function()
            {
                var booking;
                    var bookingsTableHTML = "<table border=1>";

                        for (booking in this.bookings)
                            {
                                bookingsTableHTML += "<tr><td>";
                                bookingsTableHTML += this.bookings[booking].getLocaleName();
                                bookingsTableHTML += "</td>";

                                bookingsTableHTML += "<td>";
                                bookingsTableHTML += this.bookings[booking].getLocalePrice();
                                bookingsTableHTML += "</td>";

                                bookingsTableHTML += "<td>";
                                bookingsTableHTML += this.bookings[booking].getLocaleGroup();
                                bookingsTableHTML += "</td>";                            

                                bookingsTableHTML += "</tr>"                            

                            }
                    bookingsTableHTML += "</table>";
                    return bookingsTableHTML;
            }

            var pricingTable = new cinema();
            pricingTable.addLocale("malaga", "£99", "Europe");
            pricingTable.addLocale("orlando", "£99", "USA");            
            pricingTable.addLocale("london", "£99", "Europe");

            document.write(pricingTable.getBookingsTable());                                        
        </script>
    </body>
</html>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting AD Object Advanced ACLs in VB.NET taleb .NET Framework 2.0 0 November 13th, 2007 07:15 AM
Object Oriented Programming jgrant C# 2005 0 March 16th, 2007 03:04 AM
Object oriented programming with VB6 james gold Pro VB 6 3 September 27th, 2003 02:31 PM
Object oriented programming with VB6 james gold VB How-To 2 September 23rd, 2003 09:29 AM
Object oriented programming with VB6 james gold Beginning VB 6 3 September 18th, 2003 02:56 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.