Limit length of listbox?
Results 1 to 8 of 8

Thread: Limit length of listbox?

  1. #1
    Junior Member
    Join Date
    Nov 2002
    Posts
    28

    Question Limit length of listbox?

    I'm using the following code to load a "Task" listbox using data from a MySQL table:

    while ($row = mysql_fetch_array($sql_result)) {
    $Task= $row["Task"];
    $option_block .= "<OPTION value=\"$Task\">$Task</OPTION>";
    }

    This task list is quite long, and IE5 on a Windows 98 PC automatically adds a scroll bar and limits the number of items displayed to 11.

    I learned today that someone viewing the same sight using Windows XP did not have a default limit to the number of items displayed in the listbox. The listbox extended beyond the top and bottom of the screen, and typing in characters (that would normally advance to entries beginning with those characters) had no effect on selecting a listbox item.

    First, can I use PHP to limit the number of rows displayed while still loading all the values into the listbox, and--if so--how?

    Second, does this Windows XP situation have to do with a PC setting? Is it a bug? Has anyone else run into this?

    Thanks!

    Timm

  2. #2
    Senior Member
    Join Date
    Mar 2001
    Location
    Portsmouth
    Posts
    784
    Firstly, when you are creating a drop down box it is the SQL that will define how many rows are returned.


    so if yo uonly want to have say 11 entries the you need to put LIMIT 11 at the end of the SQL.

    Secondly XP is on the client machine, as php is a server side scripting language it has no affect on the web page whatsoever.


    Sounds like there could be a problem with your query

    HTH


    GM
    PPPPPP

  3. #3
    Junior Member
    Join Date
    Nov 2002
    Posts
    28
    The query seems to work fine. I have tried in on several machines, and all the values display in the listbox--even on the PC using XP (and I have only tested it on one XP so far).

    If I am following your post correctly, I do not want to limit the number of rows/values loaded into the listbox; I just want to limit the number that display on screen at one time when the user clicks the down arrow on the right side of the listbox (e.g., loading all 50 states into a listbox but showing only 10 of them on screen at a time. If I can limit the number of displayed values using MySQL without limiting the number of values loaded into the listbox (e.g., I still want to add all 50 states), please let me know how.

    The best I have seen so far is adding a size="10" to the html portion of the listbox code, which unfortunately results in displaying 10 items on the screen at one time all the time; it takes up too much space.

    Again, is there a way to load all necessary values into a listbox but only display a limited number of them at a time (with a scroll bar) when the user clicks the arrow at the right side of the listbox?

    Thanks!

    Timm

  4. #4
    Senior Member
    Join Date
    Mar 2001
    Location
    Portsmouth
    Posts
    784
    Let me get this right -> (using th 50 states as an example) - You want to load all the 50 states into the list box but only have 10 of them show at any one time..

    If this is what you mean then i'm not 100% sure. A drop down list will display as many as it has room for on the screen


    GM

    Originally posted by trooper
    Firstly, when you are creating a drop down box it is the SQL that will define how many rows are returned.


    so if yo uonly want to have say 11 entries the you need to put LIMIT 11 at the end of the SQL.

    Secondly XP is on the client machine, as php is a server side scripting language it has no affect on the web page whatsoever.


    Sounds like there could be a problem with your query

    HTH


    GM
    PPPPPP

  5. #5
    Senior Member
    Join Date
    Dec 2002
    Location
    Asheville, NC
    Posts
    1,736
    The HTML tags

    <select name="NAME" size=?></select>

    Creates a scrolling select area.

    size sets the number of menu items visible before you need to scroll.

    Is this what you want to do?

  6. #6
    Junior Member
    Join Date
    Nov 2002
    Posts
    28
    No, I don't want to set up a scrolling region. I did try the size tag (not knowing that it would create a scrolling region) and determined that the size tag would not work.

    Here's what I want to do. I want to be able to display a listbox which shows a single item until the user clicks the down arrow. When the user clicks the down arrow to see additional listbox options, I want to be able to set a maximum height/number of rows of listbox options to display.

    I mistakenly assumed that this number was standard default setting. When I use I.E. 6 on my own PC to view the listboxes I created, for example, each listbox that has 11 or more entries shows a maximum number of 11 rows of entries at a time when I click the down arrow of the listbox. I did not code it to show a maximum number of 11 entries; it just does. For whatever reason, however, the PC that has XP does not show a maximum of 11 lines but attempts to show all the listbox options. If the listbox is long enough--and some of mine are--the first and last items in the listbox extend off the top and bottom of the screen. This is the action I want to try to prevent. Any ideas?

    Again, thanks!

    Timm

  7. #7
    Senior Member
    Join Date
    Dec 2002
    Location
    Asheville, NC
    Posts
    1,736
    You can't do what you are trying to do.

    These are browser specific actions that will be difficult if not impossible to control correctly on all platforms, as you are demonstrating.

    You might be able to create a layer or iframe in some browsers that you would then control using javascript and cascading stylesheets, and you could that way replicate the behavior you describe.

    If it seems very important, could I suggest that you start learning about DHTML, which would be the method you'd use to achieve this. Be prepared to learn a lot of code and concepts.

    Neither PHP nor HTML nor javascript alone will do this trick.

  8. #8
    Junior Member
    Join Date
    Nov 2002
    Posts
    28
    Okay, thanks for the info, nemonoman.

    FYI, installing Service Pack 1 on the XP PC with I.E. 6.0.2600.0000 did fix the problem.

    Timm

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
  •