Really dumb question: Access server listbox from client side

E

Eddie Clark

I'm trying to access the items in a listbox from a client-side vb script.

<asp:listbox id="ListBox1" style="Z-INDEX: 101; LEFT: 16px; POSITION:
absolute; TOP: 120px" runat="server" Width="400px" Height="104px"
AutoPostBack="True"></asp:listbox>

I've tried several different ways using document.form1.listbox1 but nothing
seems to work

Any help would be appreciated.
 
M

Mark Rae

Eddie Clark said:
I'm trying to access the items in a listbox from a client-side vb script.

<asp:listbox id="ListBox1" style="Z-INDEX: 101; LEFT: 16px; POSITION:
absolute; TOP: 120px" runat="server" Width="400px" Height="104px"
AutoPostBack="True"></asp:listbox>

I've tried several different ways using document.form1.listbox1 but
nothing seems to work

Any help would be appreciated.

<script>
for(var i = 0; i < document.form1.ListBox.length; i++)
{
if(document.form1.ListBox.options.selected)
{
alert(document.form1.ListBox.options.value + ' is selected');
}
else
{
alert(document.form1.ListBox.options.value + ' is not selected');
}
}
</script>

Also, note that JavaScript is case-sensitive, so there's no point in using
document.form1.listbox1 to try to refer to a dropdown whose id is actually
ListBox1...
 
E

Eddie Clark

Thanks Mark,

I am using vbscript but if I have to I'll use java, of course I'll have to
learn java :)

Also I'm only trying to access the first item in the list box. then I will
delete it from the server side.


Mark Rae said:
Eddie Clark said:
I'm trying to access the items in a listbox from a client-side vb script.

<asp:listbox id="ListBox1" style="Z-INDEX: 101; LEFT: 16px; POSITION:
absolute; TOP: 120px" runat="server" Width="400px" Height="104px"
AutoPostBack="True"></asp:listbox>

I've tried several different ways using document.form1.listbox1 but
nothing seems to work

Any help would be appreciated.

<script>
for(var i = 0; i < document.form1.ListBox.length; i++)
{
if(document.form1.ListBox.options.selected)
{
alert(document.form1.ListBox.options.value + ' is selected');
}
else
{
alert(document.form1.ListBox.options.value + ' is not
selected');
}
}
</script>

Also, note that JavaScript is case-sensitive, so there's no point in using
document.form1.listbox1 to try to refer to a dropdown whose id is actually
ListBox1...
 
E

Eddie Clark

Here' something I've tried

msgbox document.form1.ListBox.options[1].value

no luck

Eddie Clark said:
Thanks Mark,

I am using vbscript but if I have to I'll use java, of course I'll have to
learn java :)

Also I'm only trying to access the first item in the list box. then I
will delete it from the server side.


Mark Rae said:
Eddie Clark said:
I'm trying to access the items in a listbox from a client-side vb
script.

<asp:listbox id="ListBox1" style="Z-INDEX: 101; LEFT: 16px; POSITION:
absolute; TOP: 120px" runat="server" Width="400px" Height="104px"
AutoPostBack="True"></asp:listbox>

I've tried several different ways using document.form1.listbox1 but
nothing seems to work

Any help would be appreciated.

<script>
for(var i = 0; i < document.form1.ListBox.length; i++)
{
if(document.form1.ListBox.options.selected)
{
alert(document.form1.ListBox.options.value + ' is selected');
}
else
{
alert(document.form1.ListBox.options.value + ' is not
selected');
}
}
</script>

Also, note that JavaScript is case-sensitive, so there's no point in
using document.form1.listbox1 to try to refer to a dropdown whose id is
actually ListBox1...

 
M

Mark Rae

I am using vbscript but if I have to I'll use java, of course I'll have to
learn java :)

Firstly, the example I gave you has NOTHING WHATSOEVER to do with Java - it
is JavaScript - similar name, but totally different technology...
Also I'm only trying to access the first item in the list box. then I
will delete it from the server side.

Do you mean the first item that the user has selected...?
 
M

Mark Rae

msgbox document.form1.ListBox.options[1].value

no luck

1) You said your dropdown's ID is ListBox1, not ListBox...

2) options[1] refers to the second option in the dropdown, not the first -
to refer to the first option, use options[0]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top