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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to loop through a list and display the list item

Status
Not open for further replies.

discusmania

IS-IT--Management
Oct 24, 2000
158
0
0
AP
Hi guys....

Let say i have a list box and i want to display all value in the list box regardless of selected or not. How to do that?

Thanks
Ron
 
I hope that it is not possible to get the value unless you select the list box items.

If any other way is possible let me know.

Regards,
Mathan.
 
What do you mean by "...display all value in the list box regardless of selected or not." ??
 
Try this code

<HTML>
<BODY>
<SELECT size=6 id=&quot;list1&quot; name=&quot;list1&quot; multiple>
<OPTION value=&quot;1&quot;>1
<OPTION value=&quot;2&quot;>2
<OPTION value=&quot;3&quot;>3
<OPTION value=&quot;4&quot;>4
<OPTION value=&quot;5&quot;>5</OPTION>
</SELECT>
<br>
<input type=&quot;button&quot; value=&quot;Add&quot; onclick=&quot;doAdd()&quot;>
<br>
<SELECT size=6 id=&quot;list2&quot; name=&quot;list2&quot;>
</SELECT>
<br>
<input type=&quot;button&quot; value=&quot;Show Value&quot; onclick=&quot;doShow()&quot; id=button1 name=button1>
<div name=div1 id=div1></div>
</BODY>
<script language=&quot;javascript&quot;>

function doAdd()
{
for(i=0;i<list1.length;i++)
{
if(list1.options(i).selected)//see what element is selected
{
var list1value=list1.options(i).value;
list1.remove(i);
var listelem=document.createElement(&quot;OPTION&quot;);
listelem.text=list1value;
listelem.value=list1value;
list2.add(listelem);
i=-1;//try again from begining of list to see if selected
};
};

};
function doShow()
{
var values=&quot;&quot;;
for(i=0;i<list1.length;i++)
{
alert(values+=list1.options(i).value+&quot;\n&quot;);
};
document.all.div1.innerText=values;

}
</script>
</HTML>
________

George
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top