1

I'm having a little trouble attacking this problem and wondered if anyone could push me in the right direction. What I would like to do is have a list that's have two components, a label and value. So in essence I would like a list that looks like a table with the ability to scroll up and down (since my size is preset and I have to display all the values), I'm just not sure how to approach it.

My first approach was just to embed a table with all my values inside of a div with overflow:scroll. Which was great until I brought it into Mobile Opera, where overflow doesn't work.

For a quick fix I threw my labels and values into separate select lists, which does work and look good. Except I don't want to have to scroll them independently, i.e. the labels weren't matching their values if I scrolled one and not the other.

A quick and dirty approach I have now is just combining them as strings into a single option, but it does not really look good and I would ideally like to text-align:left / text-align:right for better viewing.

What I have so far:

    var statusVarLabel = ["label 1","label 2","label 3","label 4","label 5","label 6","label 7","label 8","label 9","label 10","label 11","label 12","label 13","label 14","label 15","label 16","label 17","label 18","label 19","label 20"];
    var statusVarInfo = ["variable 1","variable 2","variable 3","variable 4","variable 5","variable 6","variable 7","variable 8","variable 9","variable 10","variable 11","variable 12","variable 13","variable 14","variable 15","variable 16","variable 17","variable 18","variable 19","variable 20"];
    function getStatus(){
        var varContainer = document.getElementById("varContainer");
        varContainer.size = statusVarLabel.length;
        tabSpacing = 0;
        for (var i=0; i < statusVarLabel.length; i++) {
            if (tabSpacing < statusVarInfo[i].length)
                tabSpacing = statusVarInfo[i].length;
        };
        for (var i=0; i < statusVarLabel.length; i++) {
            var check = 0;
            for (var j=0; j < varContainer.length; j++) {
                if ( statusVarLabel[i] == varContainer.options[j].text.slice(0,statusVarLabel[i].length)){
                    check = 1;
                    break;
                }
            };              
            var stringSpacing = "";
            for (var k=0; k < (tabSpacing-statusVarInfo[i].length)+5; k++) {
                stringSpacing = stringSpacing + " ";
            };
            if (check == 0)
                addOption(varContainer, statusVarLabel[i] + stringSpacing + statusVarInfo[i], i);
        };          
    }

Just wondering if anyone out there has run into the same problem. I'm still a bit new to the HTML game, is there a way to embed a table or div within a list?

2 Answers 2

1

In select list elements, you can only have option and optgroup elements. Nothing else is supported.

Ideally, you could use a table with a custom JavaScript scrollbar widget; this would allow you to work around Mobile Opera's problems with overflow. But a fully functional scrollbar is quite complex and it takes time to implement. Of course you can search for a jQuery plugin or something similar, but you might have to resort to a partially functional scrollbar, for example one that does not handle dragging. Just keep in mind that when they see a scrollbar, certain users may expect that it will work exactly like a native scrollbar.

Otherwise, if you want to keep it simple, it is possible to "couple" two or more select lists so that when you scroll one, the others scroll synchronously.

For example, using the onscroll event and the scrollTop property:

HTML

<div id="varContainer">
    <select id="seVarLabels" style="text-align: left"></select>
    <select id="seVarInfos" style="text-align: right"></select>
</div>

JavaScript

var varContainer = document.getElementById("varContainer");

var seVarLabels = document.getElementById("seVarLabels");
seVarLabels.size = statusVarLabel.length;

var seVarInfos = document.getElementById("seVarInfos");
seVarInfos.size = statusVarInfo.length;


seVarLabels.onscroll =  function () {
    seVarInfos.scrollTop = this.scrollTop;
};
seVarLabels.onclick =  function () {
    seVarInfos.selectedIndex = this.selectedIndex;
}
seVarInfos.onscroll =  function () {
    seVarLabels.scrollTop = this.scrollTop;
}
seVarInfos.onclick = function () {
    seVarLabels.selectedIndex = this.selectedIndex;
}

for (var i=0; i < statusVarLabel.length; i++) {
    addOption(seVarLabels, statusVarLabel[i], i);
    addOption(seVarInfos, statusVarInfo[i], i);
}

It worked in Firefox, but I could not test it on Mobile Opera.

An inconvenient of this approach is that you will have a vertical scrollbar between the two lists; however, using CSS it should be possible to position the second list so that it hides that scrollbar by overlapping the first list by the scrollbar's width.

Sign up to request clarification or add additional context in comments.

3 Comments

This is probably the way to go for me. Didn't have any issues in mobile Opera with it. Although I did notice a little nuance; the same code in mobile IE does not actually move the scroll bar. It just pops out the select menu, where the scroll bar works fine, and then updates the viewable list position based on when you exit the popup. But the scroll bar on the main screen is always static (ie I could be viewing variables 10-15 with the scroll bar still at the upper most position).
Do you mean that the whole document should scroll?
No, the menu is only a part of the document. Since I'm limited on display size for a mobile page I went for the menu option so I could scroll through what I needed to see at the time.
0

I am getting a little lost are you trying to do the following ?

 <select>
  <optgroup label="Swedish Cars">
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
  </optgroup>
  <optgroup label="German Cars">
    <option value="mercedes">Mercedes</option>
    <option value="audi">Audi</option>
  </optgroup>
 </select>

5 Comments

not really, I want to group them horizontally, kind of like this: [ Label Value] (scrollbar) where I can scroll through a list of labels and their corresponding values. I'm not wanting to bring up the whole list, just scroll through it.
I think some of your problems are coming from opera mobile having incomplete support quirksmode.org/m/css.html, You may want to have a clean way of displaying what your doing normally and have completely reworked js that will work for your mobile platform. I am not sure you will get completely what you want trying to write one javascript that will solve all your problems.
That's one of the things I was afraid of. I have a detect mobile platform routine and can hash it out if it's mobile Opera. Do you have any suggestions on displaying it for mobile Opera? I could break down and make a really complicated visible/hidden div collection, but that seems like a lot of overhead. The only reason I went to Mobile Opera was to get away from mobile IE (v5? I think). If you know another mobile browser I could install it, that might solve my issue. I've had limited success with NetFront and Iris but Fennec bogs down my old pda. Thanks again for the quick responses!
Not really sure, When supporting mobile browsers I try to limit myself to safari and chrome for iPhone and Android devices.
Indeed, mobile IE has become a pain. Unfortunatly I'm stuck with WinCE on my pda.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.