Results 1 to 3 of 3

Thread: Toggle Sorting - Inventory - Price / Name

  1. #1
    Join Date
    Jan 2006
    Location
    up here in my tree
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Toggle Sorting - Inventory - Price / Name

    ## Using PHP & MySQL / HTML Table

    Table = DB result output to 3 cols:
    (Item Name | Description | Pricing)

    in testing, i've tweaked my SQL from sorting by name, to sort instead by price. it would be cool to offer the user an option to toggle the sorting between product name or price-- but NOT to do it via another query action because that procedure takes too much time.

    I thought that perhaps i could using the "display:none" toggle hidden div trick, as in:
    Code:
    $javascript = '<!--
    function switchMenu(obj) {
    	var el = document.getElementById(obj);
    	if ( el.style.display != "block" ) {
    		el.style.display = "block";
    	}
    	else {
     
    		el.style.display = "none";
    	}
    }
    //-->';
    to simply "hide", for instance, a price-sorted table and then on-toggle, the price-sorted would be visible and the former would then become hidden-- so through this manner, we can eliminate the time needed to query the db, and there's no need to reload the page.

    i couldn't figure out how to do the "flip-flop" aspect of it. it's easy to "hide / display / hide / etc" the single table element (thanks to what i've learned from the excellent teachers here a DD!), but 2 elements "at once" seems a whole different animal.

    THANK YOU! i look forward to what reading any replies!
    PS. i thought also perhaps the problem could be solved by dynamically changing the name of the ID in the javascript code-- but i don't know how to do it / if it's possible... as it would probably be the more sensible / easy solution?
    Last edited by a_design_interactive; 03-18-2007 at 02:01 AM. Reason: commentary about an idea

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    If you are only switching between two items, why not try the following.

    Code:
    function switchMenu(show, hide) {
    	var hide_obj = document.getElementById(hide);
            var show_obj = document.getElementById(show);
    
            show_obj.style.display = "block";
            hide_obj.style.display = "none";
    }
    Then, in your HTML code (where you define the id[s] of the element[s]), place the following (as an example):

    Code:
    <a href="#" onclick="switchMenu('price', 'description'); return false;">Sort By Price</a>
    
    <div id="price" style="display: block;">This is the price div</div>
    Replace the part in red with the div/table id that you want to show, and the part in blue with the div/table id you want to hide.

    If you wanted to show a third sorting option, simply add a third attribute to the function.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Jan 2006
    Location
    up here in my tree
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    hey there, T-3!


    this looks cool-- learning something new each time i come back w/ a question, which is a good thing!

    actually-- it's sort of half going over my head, and half sinking in. i probably won't get it until i play around w/ it a bit. i understand the whole thing about 1, 2, 3 or more attributes being passed into / processed by the function -- and what they represent-- the id="" of the DIV, right? but-- i guess it's the basic "built-in" stuff where i'm getting lost or something. i dunno...

    let me ask you this:
    what does it mean to write:
    Code:
    var hide_obj = document.getElementById(hide);
    ???
    i can see the other part more easily
    Code:
            show_obj.style.display = "block";
    i see that as, show_obj is a var you defined above, and it is supposed to affect the display style : block (from style.display = "block"), but how we get the actual "action"... i think it's the function of the document.getElementById() that i don't understand. i need to reference that built-in function, and gain a better understanding-- otherwise, i'm going to remain confused on how these hand-rolled functions are made to work.

    i'll get it... but i need to learn more of the fundamentals yet, obviously
    Last edited by a_design_interactive; 03-21-2007 at 06:16 PM.

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
  •