Results 1 to 5 of 5

Thread: Easy question : SELECT and multiple selections

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2000
    Location
    Québec, Canada
    Posts
    212

    Question Easy question : SELECT and multiple selections

    Hi,

    I'm using a select to display the result of a search. Now the user can select multiple rows and I'm opening a new page containing only those records.

    What I want to know is how to determine which rows are selected since mydoc.myform.mylist.selectedindex only returns the index of the last selected item, same for value.

    Regards,

    El-Nino

  2. #2
    Fanatic Member Psyrus's Avatar
    Join Date
    Jul 2000
    Location
    NJ
    Posts
    602
    To get multiple values you have to loop through the options[] array and check the SELECTED property.


    <html>
    <head>
    <title></title>
    <script LANGUAGE = "JavaScript">
    var buttonClicked = false;

    function getRows(){

    var intIndex;

    for(intIndex = 0;intIndex < frmMain.sctNames.length;intIndex++){

    if(frmMain.sctNames.options[intIndex].selected){
    frmMain.txtResult.value += frmMain.sctNames.options[intIndex].index;
    alert(frmMain.sctNames.options[intIndex].index);
    }//end if

    }//end for

    }//end function

    </script>
    </head>
    <body>
    <form NAME = "frmMain">
    <select NAME = "sctNames" MULTIPLE>
    <option>Harry Henderson</option>
    <option>John LeClair</option>
    <option>Mario Lemieux</option>
    <option>Jeremy Roenick</option>
    </select>
    <br>
    <input TYPE = "text" NAME = "txtResult">
    <br>
    <input TYPE = "button" VALUE = "Get Rows" ONCLICK = "getRows();">
    </form>
    </body>
    </html>



    Chris
    Chris

    VB 6.0 Calendar App Video Gamers Group
    Don't forget to rate people if they helped you.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2000
    Location
    Québec, Canada
    Posts
    212
    Ok, thanks for the reply Psyrus !

    I tried your idea, but my Vbscript code doesn't work
    Any idea wh'ats wrong with it ?
    Code:
    	Sub AddElem()
    		Dim i
    		Dim strRecherche
    		
    		With document.frmRechercher
    			For i = 1 to <%= rs.RecordCount %>
    				If .lstRechercher.options(i).selected Then
    					strRecherche = strRecherche & .lstRechercher.options(i).value & "*!*"
    				End if
    			Next
    		End With
    		
    		msgbox strRecherche
    	End Sub
    Regards,

    El-Nino

  4. #4
    Fanatic Member Psyrus's Avatar
    Join Date
    Jul 2000
    Location
    NJ
    Posts
    602
    The array starts at 0 index so start your loop there. I think you have to change it to options[], maybe not in VBScript though.


    Chris
    Chris

    VB 6.0 Calendar App Video Gamers Group
    Don't forget to rate people if they helped you.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Oct 2000
    Location
    Québec, Canada
    Posts
    212
    That did the trick !

    Thanks a lot again !
    Regards,

    El-Nino

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width