Reset listbox select items to selectedindex=0 - Javascript

This is a discussion on Reset listbox select items to selectedindex=0 - Javascript ; Hi! I have several vb .net listbox with several items in a search page. Users filter their search criteria by selecting items. If all listboxes.SelectedIndex=0 then the search retreives all items. Requirement: A client-side button to reset all listboxes to ...

+ Reply to Thread
Results 1 to 3 of 3

Reset listbox select items to selectedindex=0

  1. Default Reset listbox select items to selectedindex=0

    Hi!

    I have several vb.net listbox with several items in a search page. Users
    filter their search criteria by selecting items. If all
    listboxes.SelectedIndex=0 then the search retreives all items.

    Requirement:

    A client-side button to reset all listboxes to selected index = 0

    How to do it in javascript?

    tried:

    <head>
    function reset()
    {
    document.Form1.listbox1.selectedIndex = 0;
    document.Form1.listbox2.selectedIndex = 0;
    ....
    }
    </head>

    and onclick of the button ... onClick="reset()"

    but I get an error "object does not support this method or property..."

    please help

    thanks

    berrucho



  2. Default Re: Reset listbox select items to selectedindex=0

    "berrucho" <berrucho@oninet.pt> wrote in message
    news:ObjUtzUcDHA.1488@TK2MSFTNGP12.phx.gbl...
    > Hi!
    >
    > I have several vb.net listbox with several items in a search page. Users
    > filter their search criteria by selecting items. If all
    > listboxes.SelectedIndex=0 then the search retreives all items.
    >
    > Requirement:
    >
    > A client-side button to reset all listboxes to selected index = 0
    >
    > How to do it in javascript?


    Check this sample:

    <html>
    <head>

    <head>
    <script type="text/javascript">
    function resetLists(){
    document.forms["form1"].elements["sel1"].selectedIndex = 0;
    document.forms["form1"].elements["sel2"].selectedIndex = 0;
    }
    </script>
    <body>
    <form id="form1">
    <select name="sel1">
    <option value="0">None</option>
    <option value="1">One</option>
    <option value="2">Two</option>
    </select>
    <select name="sel2">
    <option value="0">None</option>
    <option value="1">One</option>
    <option value="2">Two</option>
    </select>
    <button onclick="resetLists()">Reset lists</button>
    </form>
    </body>
    </html>

    Or, if you want to reset *all* SELECT elements in form1, you could use this
    function:
    resetLists(){
    var selects = document.forms["form1"].getElementsByTagName("SELECT");
    for (var i=0; i<selects.length; i++){
    selects.item(i).selectedIndex = 0;
    }
    }



  3. Default Re: Reset listbox select items to selectedindex=0

    Many thank's Vjekoslav
    Worked perfectly
    I was doing it server side...........
    berrucho

    "Vjekoslav BegoviŠ" <vjbegovic@inet.hr> wrote in message
    news:uARCbhVcDHA.652@tk2msftngp13.phx.gbl...
    > "berrucho" <berrucho@oninet.pt> wrote in message
    > news:ObjUtzUcDHA.1488@TK2MSFTNGP12.phx.gbl...
    > > Hi!
    > >
    > > I have several vb.net listbox with several items in a search page. Users
    > > filter their search criteria by selecting items. If all
    > > listboxes.SelectedIndex=0 then the search retreives all items.
    > >
    > > Requirement:
    > >
    > > A client-side button to reset all listboxes to selected index = 0
    > >
    > > How to do it in javascript?

    >
    > Check this sample:
    >
    > <html>
    > <head>
    >
    > <head>
    > <script type="text/javascript">
    > function resetLists(){
    > document.forms["form1"].elements["sel1"].selectedIndex = 0;
    > document.forms["form1"].elements["sel2"].selectedIndex = 0;
    > }
    > </script>
    > <body>
    > <form id="form1">
    > <select name="sel1">
    > <option value="0">None</option>
    > <option value="1">One</option>
    > <option value="2">Two</option>
    > </select>
    > <select name="sel2">
    > <option value="0">None</option>
    > <option value="1">One</option>
    > <option value="2">Two</option>
    > </select>
    > <button onclick="resetLists()">Reset lists</button>
    > </form>
    > </body>
    > </html>
    >
    > Or, if you want to reset *all* SELECT elements in form1, you could use

    this
    > function:
    > resetLists(){
    > var selects = document.forms["form1"].getElementsByTagName("SELECT");
    > for (var i=0; i<selects.length; i++){
    > selects.item(i).selectedIndex = 0;
    > }
    > }
    >
    >





+ Reply to Thread

Similar Threads

  1. Trouble setting the selectedindex of a listbox
    By Application Development in forum DOTNET
    Replies: 6
    Last Post: 10-25-2007, 10:15 AM
  2. Identifying listbox items
    By Application Development in forum TCL
    Replies: 3
    Last Post: 07-06-2007, 04:32 AM
  3. ListBox crash when accessing SelectedIndex
    By Application Development in forum DOTNET
    Replies: 1
    Last Post: 06-10-2007, 07:29 PM
  4. how to Right Align the ListBox items ?
    By Application Development in forum DOTNET
    Replies: 1
    Last Post: 05-21-2007, 08:04 AM
  5. Adding items to a listbox
    By Application Development in forum DOTNET
    Replies: 9
    Last Post: 10-10-2003, 09:29 AM