SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: Price Updater

  1. #1
    SitePoint Member
    Join Date
    Apr 2003
    Location
    Florida
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Price Updater

    Hello. I am working on a script that will display prices relative to each other. When a user click a price the other prices in that category automatically update. For an example go here: http://67.8.107.77:81/index.html. However the way I am doing it, is very painstaking and requires alot of editing.

    Is there another, more simpler way of doing this?

    Feel free to view the source to see how I am currently doing this.

    Thanks in advance for your help.

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, for the process to be more simple, the code must be more advanced.

    I've been considering writing an object/class to handle stuff like this for a while, I just haven't found the time.

    I wish I could quickly give you advice about this, but it's really quite complicated.

    My best, quick recommendation, is to practice abstracting processes that are repetitive. Example:

    Instead of this
    Code:
    document.getElementById("totalSpanTop" ).innerHTML = "$" + subTotal;
    document.getElementById("totalSpanBottom" ).innerHTML = "$" + subTotal;
    Do it this way
    Code:
    setTotal( 'totalSpanTop', subTotal );
    setTotal( 'totalSpanBottom', subTotal );
    
    function setTotal( elemId, total )
    {
    	document.getElementById( elemId ).innerHTML = subTotal.toCurrency();
    }
    
    /* Converts number to a currency string
    ------------------------------------------- */
    Number.prototype.toCurrency = function()
    {
    	return "$" + ( this * 100 ).round( 0 ).toString().replace( /(\d\d)$/, ".$1" );
    }
    
    /* Rounds number to given places
    ------------------------------------------- */
    Number.prototype.round = function( places )
    {
    	var rounder = Math.pow( 10, places );
    	return Math.round( this * rounder ) / rounder;
    }
    What I've done here does several things. First, the process of writing a total to an element is in one place. Second, I now have methods to handle number rounding and currency creation, which not only serve their purpose in this example, but can be reused many other places in the script. This process is called abstraction. Basically, functions should be two things

    1) As simple and concise as possible
    2) As reusable as possible

    Try it out, and let me know. I left room for improvement in this code, so I'll see what you do with it
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    SitePoint Member
    Join Date
    Apr 2003
    Location
    Florida
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks... I will put your suggestions into my code. I asked this a while back on another site, and I got a great response.. However.. That was a few servers ago, and a few hard drive formats. So I lost it. The site was something like dev********forums.*** im not sure.... I think the site had an orange layout. If you know what Im talking about, please give me the link.

    Thanks for your help.

  4. #4
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://forums.devshed.com
    www.devarticles.com/forums/

    That's all I can think of right now
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  5. #5
    SitePoint Member
    Join Date
    Apr 2003
    Location
    Florida
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nope it wasn't any of those.. Thanks for the suggestions though

  6. #6
    American't awestmoreland's Avatar
    Join Date
    Sep 2002
    Location
    Grand Rapids, MI
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by drews
    The site was something like dev********forums.*** im not sure.... I think the site had an orange layout. If you know what Im talking about, please give me the link.
    I think that SPF (this site) used to have an Orange layout back before they changed the design to use this CSS madness ...although I could have imagined it.
    From the English nation to a US location.

  7. #7
    SitePoint Member
    Join Date
    Apr 2003
    Location
    Florida
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, I know it wasn't this site. It was something different. Oh, well I guess I'm just stuck trying to find the old version of it.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •