Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Issue resetting ScrollTop to zero

Status
Not open for further replies.

cawthor

Programmer
May 31, 2001
89
US
I've included some sample code below. If I scroll down a few items in a multi select box, then reset the ScrollTop to zero, the list resets to the first element correctly. However, if you then click the scroll down arrow, it will jump to the next value before the scrolltop reset. Eg. Scroll down 3 clicks to 'Test 4', click 'reset', click down arrow once. First value displayed is 'Test 5' instead of 'Test 2'.

<SELECT name="test" multiple size="4">
<option>Test 1
<option>Test 2
<option>Test 3
<option>Test 4
<option>Test 5
<option>Test 6
<option>Test 7
<option>Test 8
<option>Test 9
</SELECT>
<a href="javascript:void(0);" onclick="document.all['test'].scrollTop=0;">reset</a>
 
You might consider setting the selectedIndex as well...

Code:
<select [b]id="testSelect"[/b] multiple size="4">
<option>Test 1
<option>Test 2
<option>Test 3
<option>Test 4
<option>Test 5
<option>Test 6
<option>Test 7
<option>Test 8
<option>Test 9
</select>
[s]<a href="javascript:void(0);" onclick="document.all['test'].scrollTop=0;">reset</a>[/s]
<span style="text-decoration: underline;color:blue;" onclick="document.[b]getElementById('testSelect')[/b].selectedIndex = 0;">Reset</span>
It worked nicely for me in Fx 2 on MacOSX - but that's probably not your target browser [smile]

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top