Really dumb question: Access server listbox from client side

Discussion in 'ASP .Net' started by Eddie Clark, Oct 9, 2004.

  1. Eddie Clark

    Eddie Clark Guest

    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.
     
    Eddie Clark, Oct 9, 2004
    #1
    1. Advertising

  2. Eddie Clark

    Mark Rae Guest

    "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.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...
     
    Mark Rae, Oct 9, 2004
    #2
    1. Advertising

  3. Eddie Clark

    Eddie Clark Guest

    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.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...
    >
     
    Eddie Clark, Oct 10, 2004
    #3
  4. Eddie Clark

    Eddie Clark Guest

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

    >
    >
     
    Eddie Clark, Oct 10, 2004
    #4
  5. Eddie Clark

    Mark Rae Guest

    "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...?
     
    Mark Rae, Oct 10, 2004
    #5
  6. Eddie Clark

    Mark Rae Guest

    "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]
     
    Mark Rae, Oct 10, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Valerian John
    Replies:
    6
    Views:
    5,184
    Valerian John
    May 17, 2004
  2. Replies:
    1
    Views:
    266
    Mark A. Odell
    Jul 16, 2004
  3. Aryeh M. Friedman

    really dumb question

    Aryeh M. Friedman, Oct 29, 2007, in forum: Java
    Replies:
    6
    Views:
    357
    Sherman Pendley
    Oct 30, 2007
  4. Joe Abou Jaoude
    Replies:
    2
    Views:
    192
    Joe Abou Jaoude
    Nov 18, 2004
  5. Jerry C.
    Replies:
    8
    Views:
    278
    Uri Guttman
    Nov 23, 2003
Loading...

Share This Page