×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

Thank you very much, your post helped me to find a solution, partly :-(.

本文发表在 rolia.net 枫下论坛My problem is caused by mulitple select box, I want to show mulitple selected item ,

<select id=s2[] name=s2 MULTIPLE size=6>
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
<option value=4 >4</option>
<option value=5>5</option>
<option value=6>6</option>
<option value=7>7</option>
<option value=8>8</option>
<option value=9>9</option>
<option value=10>10</option>
<option value=11>11</option>
<option value=12>12</option>
<option value=13>13</option>
<option value=14 selected>14</option>
<option value=15 selected>15</option>
<option value=16>16</option>
</select>

In Firefox/Mozilla, when the page is loaded, the select automatically scrolldown to the first selected item, which is what I want. but in IE , it stay in the first low.

I tried :
<input type=button value=test onclick="Javascript:moveSelect()">
<script language="JavaScript">
<!--
var ie5=document.all
var ns6=document.getElementById&&!document.all
function FIND(item) {
if( window.mmIsOpera ) return(document.getElementById(item));
if (document.all) return(document.all[item]);
if (document.getElementById) return(document.getElementById(item));
return(false);
}
function moveSelect()
{
obj= FIND('s2');
idx= obj.selectedIndex;
obj.selectedIndex=idx;
}
//-->
</script>

The select did scroll down, but I lost a selection. so the final solution is

function moveSelect1()
{
obj= FIND('s2');
var length= obj.options.length;
var arr =new Array();
for ( i=0;i<length;i++)
{
arr[i]=obj.options[i].selected;
}

idx= obj.selectedIndex;
obj.selectedIndex=idx;

for ( i=0;i<length;i++)
{
obj.options[i].selected=arr[i];
}

}

But unfortunately, It didn't work on safari :-(更多精彩文章及讨论,请光临枫下论坛 rolia.net
Report

Replies, comments and Discussions:

  • 工作学习 / 专业技术讨论 / Javascript question, any highhand?
    本文发表在 rolia.net 枫下论坛I need to dynamically scroll down a select dropdown box in IE by javascript .

    I found a Property scrollTop from msdn:

    http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/scrolltop.asp

    tried the following code but it doesn't work in IE.
    <script language="JavaScript">
    <!--
    function test()
    {
    //alert(document.all.s2); //s2 is a object.
    document.all.s2.scrollTop +=20;
    }
    //-->
    </script>

    <table><tr><td>
    <select id=s2 name=s2 size=6>
    <option value=1>1</option>
    <option value=2>2</option>
    <option value=3>3</option>
    <option value=4>4</option>
    <option value=5>5</option>
    <option value=6>6</option>
    <option value=7>7</option>
    <option value=8>8</option>
    <option value=9>9</option>
    <option value=10>10</option>
    <option value=11>11</option>
    <option value=12>12</option>
    <option value=13>13</option>
    <option value=14>14</option>
    <option value=15>15</option>
    <option value=16>16</option>
    </select>
    </td>
    <td><input type=button value=test onclick="Javascript:test()"></td>
    </tr></table>

    select's scrollTop in IE is always 0.My IE version is 6.0.28.
    Surperisely the code is working in Firefox.

    Since it's listed in MSDN, I suppose it should work in IE.

    Thanks.更多精彩文章及讨论,请光临枫下论坛 rolia.net
    • This property's value equals the current vertical offset of the content within the scrollable range it doesnot matter with "dynamically scroll down a select dropdown box "
      • what I want is to change the "current vertical offset of the content within the scrollable range" by javascript.
        • try document.frmWin1.s2.selectedIndex = an offset value, then document.frmWin1.s2.selectedIndex = -1, but you need to keep previousselectedIndex in a hidden field.
          • Thank you very much, your post helped me to find a solution, partly :-(.
            本文发表在 rolia.net 枫下论坛My problem is caused by mulitple select box, I want to show mulitple selected item ,

            <select id=s2[] name=s2 MULTIPLE size=6>
            <option value=1>1</option>
            <option value=2>2</option>
            <option value=3>3</option>
            <option value=4 >4</option>
            <option value=5>5</option>
            <option value=6>6</option>
            <option value=7>7</option>
            <option value=8>8</option>
            <option value=9>9</option>
            <option value=10>10</option>
            <option value=11>11</option>
            <option value=12>12</option>
            <option value=13>13</option>
            <option value=14 selected>14</option>
            <option value=15 selected>15</option>
            <option value=16>16</option>
            </select>

            In Firefox/Mozilla, when the page is loaded, the select automatically scrolldown to the first selected item, which is what I want. but in IE , it stay in the first low.

            I tried :
            <input type=button value=test onclick="Javascript:moveSelect()">
            <script language="JavaScript">
            <!--
            var ie5=document.all
            var ns6=document.getElementById&&!document.all
            function FIND(item) {
            if( window.mmIsOpera ) return(document.getElementById(item));
            if (document.all) return(document.all[item]);
            if (document.getElementById) return(document.getElementById(item));
            return(false);
            }
            function moveSelect()
            {
            obj= FIND('s2');
            idx= obj.selectedIndex;
            obj.selectedIndex=idx;
            }
            //-->
            </script>

            The select did scroll down, but I lost a selection. so the final solution is

            function moveSelect1()
            {
            obj= FIND('s2');
            var length= obj.options.length;
            var arr =new Array();
            for ( i=0;i<length;i++)
            {
            arr[i]=obj.options[i].selected;
            }

            idx= obj.selectedIndex;
            obj.selectedIndex=idx;

            for ( i=0;i<length;i++)
            {
            obj.options[i].selected=arr[i];
            }

            }

            But unfortunately, It didn't work on safari :-(更多精彩文章及讨论,请光临枫下论坛 rolia.net
            • oh, it's easy than I thought acturally: obj= FIND('s2'); idx= obj.selectedIndex; obj.options[idx].selected=true;
    • highhand这个词有吗?英文高手指教一下英文高手怎么讲
      • guru