www.webdeveloper.com
Results 1 to 8 of 8

Thread: Is there a way to hide a select menu without disabling the functionality?

  1. #1
    Join Date
    Feb 2011
    Posts
    8

    Is there a way to hide a select menu without disabling the functionality?

    Hi,

    I have an internet shop detail page, on which the user can choose size and version of a product.

    Some of our products have only a size option, or only a version option. For these products I would like to hide the select menu, that is not needed. However, when I do so another functionality of the select menu (changing item no. and price on change) no longer work.

    Is there a way to have a select menu not display, while the "on change" functionality still works?

    This is the code, I have been using, to hide the select menu, when the respective data field is empty:
    <?php if (!empty($row_rsversion['version'])) { // Show if recordset not empty ?>

    I have very limited experience with PHP.

    Could someone help me?

  2. #2
    Join Date
    Jul 2007
    Location
    Wisconsin
    Posts
    468
    that bit of code looks to be fine (barring the missing } to close the if statement; assuming its further down the page), but it's hard to see if something else is causing a problem without any other code.

    One option would be to use CSS to display: none the select if it's empty.

    HTML Code:
    <style type="text/css">
    .hide {display: none;}
    .show {display: block}
    </style>
    PHP Code:
    if ( (!isset($row_rsversion['version'])) || ($row_rsversion['version'] == "") )

    $tmpElementClass "hide"
    }
    else 
    {
    $tmpElementClass "show";

    Then just output the element like normal, but add the class:

    PHP Code:
    <select class="<?php echo $tmpElementClass?>" id="foo">
    ...
    </select>

  3. #3
    Join Date
    Feb 2011
    Posts
    8
    Hi OctoberWind,

    Thank you for your reply. I really appreciate your help.

    Yes, there was a closing statement further down. And it hid the select menus, but it didn't work as far as item number and price change go, when selecting a different version.

    I tried your code, and in part it actually worked. Or I should better say, for the version selection it worked. It worked for both, products with version and size selection, and products with just version selection

    I tried changing the code a little to accommodate products with just size selection, but as soon as I put the output code into the select menu, everything stopped working.

    I tried this:

    <?php
    if ( (!isset($row_rsversion['version'])) || ($row_rsversion['version'] == "") )
    {
    $tmpElementClassVersion = "hide";
    }
    else
    {
    $tmpElementClassVersion = "show";
    }
    ?>
    <?php
    if ( (!isset($row_rssizedefault['size'])) || ($row_rssizedefault['size'] == "") )
    {
    $tmpElementClassSize = "hide";
    }
    else
    {
    $tmpElementClassSize = "show";
    }
    ?>

    But when I put this
    class="<?php echo $tmpElementClassSize; ?>
    in the size select menu, neither version or size selection change price and item number.

  4. #4
    Join Date
    Jul 2007
    Location
    Wisconsin
    Posts
    468
    hmm... i would have to see the entire script to see what's up. there's no reason adding a class would disrupt functionality.

  5. #5
    Join Date
    Feb 2011
    Posts
    8
    Hi Octoberwind,

    I changed the code a little (adding version_id instead of version, and size_id instead of size), and setting the if statement to the values 8 or 13 (the values for no choice).


    <?php
    if ( (!isset($row_rsversion['version_id'])) || ($row_rsversion['version_id'] == "13") )
    {
    $tmpElementClassVersion = "hide";
    }
    else
    {
    $tmpElementClassVersion = "show";
    }
    ?>
    <?php
    if ( (!isset($row_rssizedefault['size_id'])) || ($row_rssizedefault['size_id'] == "8") )
    {
    $tmpElementClassSize = "hide";
    }
    else
    {
    $tmpElementClassSize = "show";
    }
    ?>

    This now displays the result, I wanted. For example a product without version choice no longer shows the version select menu, and when changing the size, the display of item number and price change too.

    It brought about another problem though. When submitting, the chosen product is not passed on to the cart page correctly. For example, a product is available in sizes S, M and L. No matter what I choose, S is passed on.

    This code is used to pass on the value for the size.
    $ATC_itemSize = "".$row_rspricelookup['size'] .""?$row_rspricelookup['size']$row_rspriceNoSize['size']!=""?$row_rspriceNoSize['size']$row_rspriceNoVersion['size']!=""?$row_rspriceNoVersion['size']:$row_rspriceNoVersionNoSize['size']));// column binding

    The other values are passed on similarly.

    I don't see, why a style would affect, what is being passed onto the cart page.

    Thank you for your help. I think the company, that sells the shop software, will know why. I will post back with their recommendations

    PS: I don't know how to post code correctly. The little confused faces in the code should have been column, opening bracket.

  6. #6
    Join Date
    Jul 2007
    Location
    Wisconsin
    Posts
    468
    post your code inside of the php tags:

    [PHP ]code goes here, without the spaces in the tags.[/PHP ]

  7. #7
    Join Date
    Feb 2011
    Posts
    8
    Hi OctoberWind,

    The tech support said, not to hide a select menu with css.

    But I think I may have found the solution by combining the use of php and css. I duplicated the select menu, then hide the first select menu, if there is no version option, both with php and css. The other select menu only shows, if there is a version option (with php).

    It is probably very unconventional, and took me a while to figure out. Serious programmers will probably cry out in horror, but here is the code I used. The result is two select menus (one for version, one for size), with the non-relevant menu hidden, the correct item passed onto the cart and the price change feature. 13 and 8 respectively are the ids for zero values.

    Thank you for your help, this would not have worked without it

    PHP Code:
    <p> 
                      <?php if ($row_rsversion['version_id'] == "13") { // Show if recordset empty ?> 
                        <select class="<?php echo $tmpElementClassVersion?> name="SelectVersion" id="SelectVersion" onchange="WA_FilterAndPopulateSubList(rssize_WAJA,MM_findObj('SelectVersion'),MM_findObj('SelectSize'),0,0,false,': ');showprice()"> 
                          <?php 
    do {   
    ?> 
                          <option value="<?php echo $row_rsversion['version_id']?>"<?php if (!(strcmp($row_rsversion['version_id'], $row_rsversion['version']))) {echo "selected=\"selected\"";} ?>><?php echo $row_rsversion['version_compound']?></option> 
                          <?php 
    } while ($row_rsversion mysql_fetch_assoc($rsversion)); 
      
    $rows mysql_num_rows($rsversion); 
      if(
    $rows 0) { 
          
    mysql_data_seek($rsversion0); 
          
    $row_rsversion mysql_fetch_assoc($rsversion); 
      } 
    ?> 
                        </select> 
                        <?php // Show if recordset empty ?> 
                        <?php if ($row_rsversion['version_id'] != "13") { // Show if recordset not empty ?> 
                        <select name="SelectVersion" id="SelectVersion" onchange="WA_FilterAndPopulateSubList(rssize_WAJA,MM_findObj('SelectVersion'),MM_findObj('SelectSize'),0,0,false,': ');showprice()"> 
                          <?php 
    do {   
    ?> 
                          <option value="<?php echo $row_rsversion['version_id']?>"<?php if (!(strcmp($row_rsversion['version_id'], $row_rsversion['version']))) {echo "selected=\"selected\"";} ?>><?php echo $row_rsversion['version_compound']?></option> 
                          <?php 
    } while ($row_rsversion mysql_fetch_assoc($rsversion)); 
      
    $rows mysql_num_rows($rsversion); 
      if(
    $rows 0) { 
          
    mysql_data_seek($rsversion0); 
          
    $row_rsversion mysql_fetch_assoc($rsversion); 
      } 
    ?> 
                        </select> 
                        <?php // Show if recordset not empty ?>    
                      </p> 
                      <p> 
                          <?php if ($row_rssizedefault['size_id'] == "8") { // Show if recordset empty ?> 
                        <select class="<?php echo $tmpElementClassSize?> name="SelectSize" id="SelectSize" onchange="showprice()"> 
                          <?php 
    do {   
    ?> 
                          <option value="<?php echo $row_rssizedefault['size_id']?>"<?php if (!(strcmp($row_rssizedefault['size_id'], $row_rssize['size']))) {echo "selected=\"selected\"";} ?>><?php echo $row_rssizedefault['size']?></option> 
                          <?php 
    } while ($row_rssizedefault mysql_fetch_assoc($rssizedefault)); 
      
    $rows mysql_num_rows($rssizedefault); 
      if(
    $rows 0) { 
          
    mysql_data_seek($rssizedefault0); 
          
    $row_rssizedefault mysql_fetch_assoc($rssizedefault); 
      } 
    ?> 
                        </select> 
                        <?php // Show if recordset empty ?> 
                        <?php if ($row_rssizedefault['size_id'] != "8") { // Show if recordset not empty ?> 
                        <select name="SelectSize" id="SelectSize" onchange="showprice()"> 
                          <?php 
    do {   
    ?> 
                          <option value="<?php echo $row_rssizedefault['size_id']?>"<?php if (!(strcmp($row_rssizedefault['size_id'], $row_rssize['size']))) {echo "selected=\"selected\"";} ?>><?php echo $row_rssizedefault['size']?></option> 
                          <?php 
    } while ($row_rssizedefault mysql_fetch_assoc($rssizedefault)); 
      
    $rows mysql_num_rows($rssizedefault); 
      if(
    $rows 0) { 
          
    mysql_data_seek($rssizedefault0); 
          
    $row_rssizedefault mysql_fetch_assoc($rssizedefault); 
      } 
    ?> 
                        </select> 
                        <?php // Show if recordset not empty ?> 
                      </p>

  8. #8
    Join Date
    Feb 2011
    Posts
    8

    Thanks

    Hi OctoberWind,

    just wanted to say thanks again. I ran into another problem, where I had to hide a button, if the user was located in certain countries, and your code helped me again.

    Thanks !!!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles