Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Really dumb question: Access server listbox from client side

Reply
Thread Tools

Really dumb question: Access server listbox from client side

 
 
Eddie Clark
Guest
Posts: n/a
 
      10-09-2004
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.


 
Reply With Quote
 
 
 
 
Mark Rae
Guest
Posts: n/a
 
      10-09-2004
"Eddie Clark" <> wrote in message
news:%236v%...
> 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[i].selected)
{
alert(document.form1.ListBox.options[i].value + ' is selected');
}
else
{
alert(document.form1.ListBox.options[i].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...


 
Reply With Quote
 
 
 
 
Eddie Clark
Guest
Posts: n/a
 
      10-10-2004
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" <> wrote in message
news:...
> "Eddie Clark" <> wrote in message
> news:%236v%...
>> 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[i].selected)
> {
> alert(document.form1.ListBox.options[i].value + ' is selected');
> }
> else
> {
> alert(document.form1.ListBox.options[i].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...
>



 
Reply With Quote
 
Eddie Clark
Guest
Posts: n/a
 
      10-10-2004
Here' something I've tried

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

no luck

"Eddie Clark" <> wrote in message
news:%...
> 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" <> wrote in message
> news:...
>> "Eddie Clark" <> wrote in message
>> news:%236v%...
>>> 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[i].selected)
>> {
>> alert(document.form1.ListBox.options[i].value + ' is selected');
>> }
>> else
>> {
>> alert(document.form1.ListBox.options[i].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...
>>

>
>



 
Reply With Quote
 
Mark Rae
Guest
Posts: n/a
 
      10-10-2004
"Eddie Clark" <> wrote in message
news:%...

> 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...?


 
Reply With Quote
 
Mark Rae
Guest
Posts: n/a
 
      10-10-2004
"Eddie Clark" <> wrote in message
news:...

> 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]


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
server side code access the text of <asp:label> changed by client-side javascript code? nick ASP .Net 3 12-15-2004 06:26 PM
How to access client side XML data island from server side? =?Utf-8?B?YWRvbGYgZ2FybGlj?= ASP .Net 2 11-23-2004 05:16 PM
listbox changes on the client side aren't reflected on the server side Joe Abou Jaoude ASP .Net Web Controls 2 11-18-2004 12:21 PM
Dumb, dumb dumb Qestion David Napierkowski Digital Photography 6 10-31-2004 11:14 PM
ListBox items changed client-side are not available server-side Valerian John ASP .Net 6 05-17-2004 06:45 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57