How can I programming control the scrolling of a list box (SELECT) using JavaScript? I'd like to force certain elements to be selected and/or visible.

Jayesh Nazre

This is how you can control the selection for a listbox.

<html>
<head>
<script language=javascript>
function test() {
  document.frm_test.lst_id.options(1).selected = true;
  document.frm_test.lst_id.options(3).selected = true;
}
</script>
</head>
<body>

<form name=frm_test id=frm_test>

<SELECT NAME=lst_id size=4 MULTIPLE>
  <OPTION> 1 </OPTION> 
  <OPTION> 2 </OPTION> 
  <OPTION> 3 </OPTION> 
  <OPTION> 4 </OPTION> 
  <OPTION> 5 </OPTION> 
  <OPTION> 6 </OPTION> 
  <OPTION> 7 </OPTION> 
</SELECT>

<input type=button value=Click onclick=test()>
</form>

</body>
</html>
For controlling the size you have to set the size attribute of the select tag in the tag itself. There is no way by which you can later change the size of the listbox using JavaScript (but you can use the technique of DHTML by enclosing the select tag in a div tag and then regenerating the select tag using DHTML techniques).
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact