Ask a Question related to Macromedia Dynamic HTML, Design and Development.

  1. #1

    Default Any one Knows this

    Hello,

    Any expert here knows how can i add horizontal scrollbar to my listbox ,
    including the traditional vertical scroll.

    The scrollbar should be displayed only if the data exceeds the width of the
    listbox and not otherwise. (i.e if the listbox is large enough to hold data
    then the scrollbars neednot be enabled. If data exceeds the width then the
    horizontal scrollbar should be enabled. and data should be scrollable as it
    was in TEXTAREA.



    suhas2852 Guest

  2. #2

    Default Re: Any one Knows this

    I don't know how to put a horizontal scrollbar, but you can use an IFrame to
    fake this, give the following a try:

    2 files
    - main.html
    - testframe2.html



    <!------- main.html - Main Window File ------>

    <html>
    <script>
    function getSelectIndex(value, select){
    var loops = select.options.length;
    for(i=0; i<loops; i++){
    if(select.options[i].value==value){
    return i;
    }
    }
    return 0;
    }

    function addEntry(val, text){
    var objSelectitemcount;
    var found;

    objSelect = document.myform.Select2;
    objSelectitemcount = objSelect.options.length;

    //loop through and make sure entry does not already exist
    found = false;
    for(i=0;i<objSelectitemcount;i++){
    if((objSelect.options[i].text == text)&&(objSelect.options[i].value==val)){
    found=true;
    break;
    }
    }
    if(!found){
    objSelect.options[objSelectitemcount++]=new Option(text, val);
    }

    selectAll(objSelect);
    }
    function removeEntry(){
    var obj;
    objSelect = document.myform.Select2;
    objSelectitemcount = objSelect.options.length;

    var z=0;
    for(i=0;i<objSelectitemcount;i++){
    if(objSelect.options[z].selected == true){
    objSelect.options[z] = null;
    //z doesn't change since the one below shifted up.
    }else{
    z++;
    }
    }

    selectAll(objSelect);
    }
    function selectAll(objSelect){
    for(j=0;j<objSelect.options.length;j++){
    objSelect.options[j].selected = true;
    }

    }
    </script>
    <body>
    <form name="myform">
    Test

    <table>
    <tr>
    <td>
    <iframe src="testframe2b.html" width="200" height="150">
    </iframe>

    <!---<input type="hidden" name="myfield">--->

    <!---<input type="button" onClick="alert(this.form.myfield.value)"
    value="What's My Value">--->
    </td>
    <td>

    <select name="Select2" multiple size="8" style="width:200px;height:160px;">
    </select>
    </td>
    <td>
    <input type="button" onClick="removeEntry()" value="Delete Selected">
    </td>
    </tr>
    </table>

    </form>

    </body>
    </html>


    <!---------- testframe2b.html ------------------------------->
    <html>
    <head>
    <script language="JavaScript">
    function sendData(val, text){
    window.parent.addEntry(val, text);
    }
    </script>
    <style type="text/css">

    table{
    font-family: Arial,Helvetica;
    font-size: 12px;
    line-height:2.0;
    }
    a{
    text-decoration:none;
    }
    a:hover{
    background-color:#eeeeee;

    }
    </style>

    </head>
    <body >
    <form>
    <table width="600">
    <tr>
    <td nowrap>
    <a href="javascript:sendData(1, '1 - The Really Longggggggggggggg Number
    1');">1 - The Really Longggggggggggggg Number 1</a><br>
    <a href="javascript:sendData(2, '2 - The Really Longggggggggggggg Number
    2');">2 - The Really Longggggggggggggg Number 2</a><br>
    <a href="javascript:sendData(3, '3 - The Really Longggggggggggggg Number
    3');">3 - The Really Longggggggggggggg Number 3</a><br>
    <input type="hidden" name="myvalue">
    <br>
    </td>
    </tr>
    </table>
    </form>

    </body>
    </html>

    bubblocity Guest

  3. #3

    Default Re: Any one Knows this

    Just use a <div> with a fixed width for your list box, or put your list box
    inside one. Then set the CSS style or class of the <div> to "overflow:auto".

    Of course, if you data has line breaking points, you'll find that it breaks
    over lines instead of forming horizontal scrollbars. Just putit inside a
    <pre> tag if that happens, with the lines breaks where you want them and
    only where you want them.

    So your code looks like:

    <div id='listbox' style='width:250px; overflow:auto'>
    <----- or whatever width you want
    <pre>
    your content
    </pre>
    <div>

    I think the solution with the iframes was a little too complicated ;) Even
    if you wanted to use iframes you could do it much more simply than that.

    Anyway, hope that helps!

    Rob



    suhas2852 wrote:
    > Hello,
    >
    > Any expert here knows how can i add horizontal scrollbar to my
    > listbox , including the traditional vertical scroll.
    >
    > The scrollbar should be displayed only if the data exceeds the
    > width of the listbox and not otherwise. (i.e if the listbox is large
    > enough to hold data then the scrollbars neednot be enabled. If data
    > exceeds the width then the horizontal scrollbar should be enabled.
    > and data should be scrollable as it was in TEXTAREA.

    rob::digitalburn Guest

  4. #4

    Default Re: Any one Knows this

    Oh, I like rob's solution much much better!

    :D
    bubblocity Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139